How can I test if a letter in a string is uppercase or lowercase using JavaScript?
How can I test if a letter in a string is uppercase or lowercase using JavaScript
De openkb
Sommaire |
Questions
Answers
The answer by josh and maleki will return true on both upper and lower case if the character or the whole string is numeric. making the result a false result. example using josh
var character = 5 ; if (character == character.toUpperCase()) { alert ( upper case true ); } if (character == character.toLowerCase()){ alert ( lower case true ); }
another way is to test it first if it is numeric, else test it if upper or lower case example
var strings = this iS a TeSt 523 Now! ; var i=0; var character= ; while (i <= strings.length){ character = strings.charAt(i); if (!isNaN(character * 1)){ alert( character is numric ); }else{ if (character == character.toUpperCase()) { alert ( upper case true ); } if (character == character.toLowerCase()){ alert ( lower case true ); } } i++; }
Source
License : cc by-sa 3.0
http://stackoverflow.com/questions/1027224/how-can-i-test-if-a-letter-in-a-string-is-uppercase-or-lowercase-using-javascrip