Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 650
  • Last Modified:

Enforce Uppercase

Hi

I need a way to ensure people using my form use Uppercase in some fields. CSS will do this but when the form data is inserted in the table the case reverts to Lower.
The ideal situation would be if someone enteres lowercase,  on change would convert to uppercase or someone using lowercase in the field would generate an alert to use Uppercase ??
0
Camnoc
Asked:
Camnoc
1 Solution
 
gaubasmCommented:
If you tell me what database you are using and send me you insert statement, I will send you the correct insert statement with the appropriate field being stored in upper case.
0
 
BinuthCommented:
try this...
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
<script language="javascript" type="text/javascript">
 
function toUpper()
{
    if(window.event.keyCode >= 97 & window.event.keyCode <= 122)
    {
        window.event.keyCode = window.event.keyCode - 32;
    }
}
 
</script>
</head>
<body>
    <form id="form1" runat="server">
        <input id="Text1" type="text"  onkeypress="toUpper()" />
    </form>
</body>
</html>

Open in new window

0
 
TimCotteeHead of Software ServicesCommented:
Hello Camnoc,

If you are using ASP then presumably VBScript in asp. You can simply use UCase(Request.Form("FormField")) as appropriate when building your insert statement.

Though of course it does depend on what database you are using as to whether this is worthwhile, if for example you are using SQL server and have your collation set to case-insensitive then it does not matter what case the data is stored in as any condition will match both upper and lower case characters.

Regards,

TimCottee
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
CamnocAuthor Commented:
Hi All
The javascript is the best solution for  my case . Thanks for the replys

Binuth
Code works well . Thank you. Could  you add to code to allow alpha only / block numbers?
I have been using attached code to block numbers?? Cant use on Keypress twice??
Camnoc
function onKeyPressBlockNumbers(e)
{
	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	reg = /\d/;
	return !reg.test(keychar);
}
</script>

Open in new window

0
 
BinuthCommented:
try this
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
<script language="javascript" type="text/javascript">
 
function toUpper()
{
    if(window.event.keyCode >= 97 & window.event.keyCode <= 122)
    {
        window.event.keyCode = window.event.keyCode - 32;
    }
}
 
 
function onKeyPressBlockNumbers()
{
    var keychar = String.fromCharCode(window.event.keyCode);
    reg = /\d/;
    return !reg.test(keychar);
}
 
 
</script>
</head>
<body>
    <form id="form1" runat="server">
        <input id="Text1" type="text"  onkeypress="return onKeyPressBlockNumbers()" />
    </form>
</body>
</html>

Open in new window

0
 
CamnocAuthor Commented:
This will block numbers bur not working to change to upper?
I am using  onkeypress="return onKeyPressBlockNumbers()"
0
 
BinuthCommented:
Oh.. i misread your comment

now try this...
function onKeyPressBlockNumbers()
{
 
    var isValid = false;
    var keychar = String.fromCharCode(window.event.keyCode);
    reg = /\d/;
    isValid =  !reg.test(keychar);
    if(isValid)
    {
        if(window.event.keyCode >= 97 & window.event.keyCode <= 122)
        {
            window.event.keyCode = window.event.keyCode - 32;
        }
    }
    return isValid;
}

Open in new window

0
 
CamnocAuthor Commented:
Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now