Solved

check if value is lower case

Posted on 2008-10-22
11
1,488 Views
Last Modified: 2012-05-05
here's a wierd one.

I need to check if a value is lowercase or not

if(document.move_hdr.sess_user3.value.substring(4,5)== A LOWERCASE LETTER)
alert('that can't be lowercase!)

what code is there to replace 'A LOWERCASE LETTER'
0
Comment
Question by:tampa_vinnie
  • 3
  • 3
  • 2
  • +3
11 Comments
 
LVL 16

Accepted Solution

by:
sh0e earned 250 total points
ID: 22778371

if(document.move_hdr.sess_user3.value.substring(4,5).match(/[a-z]/))
alert('that can't be lowercase!');
 
//or to change it to uppercase
document.move_hdr.sess_user3.value.substring(4,5).toUpperCase();

Open in new window

0
 
LVL 18

Expert Comment

by:Morcalavin
ID: 22778379
Try this.

if(/[^A-Z]/.test(document.move_hdr.sess_user3.value.substring(4,5))
{
//lowercase or not  A - Z(like a ? or ~)
}
else
{
//matches A-Z
}

Open in new window

0
 
LVL 82

Expert Comment

by:hielo
ID: 22778385
if( /[a-z]/.test(document.move_hdr.sess_user3.value.substring(4,5)) )
      alert("that can't be lowercase!");
0
Independent Software Vendors: 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!

 
LVL 7

Expert Comment

by:ASPSQLServerCOM
ID: 22778402



**********what code is there to replace 'A LOWERCASE LETTER'

http://www.w3schools.com/jsref/jsref_toLowerCase.asp
0
 
LVL 82

Expert Comment

by:hielo
ID: 22778419
>>what code is there to replace 'A LOWERCASE LETTER'
OK, then instead of checking for lowercase, just "force" the input into upper case:
var data = String(document.move_hdr.sess_user3.value.substring(4,5)).toUpperCase();
alert( data );
0
 
LVL 82

Expert Comment

by:hielo
ID: 22778437
>>just "force" the input into upper case:
assuming of course you want only upper case. If you simply want to "remove" any lower case then use:
var data = String(document.move_hdr.sess_user3.value.substring(4,5)).replace(/[a-z]/g,'');
alert( data );
0
 
LVL 7

Expert Comment

by:ASPSQLServerCOM
ID: 22778458
var re = /[a-z]/;
      if(!re.test(document.move_hdr.sess_user3.value.substring(4,5)== )) {
       alert('that can't be lowercase!)
0
 
LVL 7

Expert Comment

by:ASPSQLServerCOM
ID: 22778476
additional ==, use the below code

var re = /[a-z]/;
      if(!re.test(document.move_hdr.sess_user3.value.substring(4,5))) {
       alert('that can't be lowercase!)}

Open in new window

0
 

Author Closing Comment

by:tampa_vinnie
ID: 31508821
thorough, accurate and prompt
thanks much!
0
 
LVL 18

Expert Comment

by:Morcalavin
ID: 22778581
@ASPSQLServerCOM
 
 Putting a ! in front of  the test effectively makes it test the opposite, so you are saying "if not lowercase, alert it is lowercase"
0
 
LVL 7

Expert Comment

by:bluV11t
ID: 22778628
alert("That can't be lowercase!");

Just in case you missed it...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

Suggested Solutions

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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.
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…

713 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