Solved

Enforce Uppercase

Posted on 2008-10-01
8
633 Views
Last Modified: 2010-04-21
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
Comment
Question by:Camnoc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 

Expert Comment

by:gaubasm
ID: 22612660
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
 
LVL 14

Expert Comment

by:Binuth
ID: 22612670
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
 
LVL 43

Expert Comment

by:TimCottee
ID: 22612681
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:Camnoc
ID: 22613022
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
 
LVL 14

Expert Comment

by:Binuth
ID: 22613111
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
 

Author Comment

by:Camnoc
ID: 22613193
This will block numbers bur not working to change to upper?
I am using  onkeypress="return onKeyPressBlockNumbers()"
0
 
LVL 14

Accepted Solution

by:
Binuth earned 500 total points
ID: 22613230
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
 

Author Closing Comment

by:Camnoc
ID: 31501889
Thank you
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question