How can I test if a letter in a string is uppercase or lowercase using JavaScript?

Joe :

How can I test if a letter in a string is uppercase or lowercase using JavaScript?

Ding Pogi :

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 numeric');
    }else{
        if (character == character.toUpperCase()) {
            alert ('upper case true');
        }
        if (character == character.toLowerCase()){
            alert ('lower case true');
        }
    }
    i++;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I make sure a string contains at least one uppercase letter, one lowercase letter, one number and one punctuation character?

How can I cleanse a String to contain only digits (0-9) and the letter X (uppercase) only, using Java and Javascript

How to uppercase even letter and lowercase odd letter in a string?

Splitting a string on an uppercase *or* lowercase letter

How do i check string to contain only letter(Uppercase & Lowercase) and at least one number only

How can I code the program to accept not only uppercase but also lowercase first letter?

How to convert uppercase letter to lowercase?

How can I convert uppercase input to the lowercase?

Check if string has letter in uppercase or lowercase

Transform first uppercase letter to lowercase in string

How can I allow uppercase letter with sed?

How to check whether a string contains lowercase letter, uppercase letter, special character and digit?

How to convert 1 letter from uppercase to lowercase that isn't the first letter in Javascript

How can I indent a string when lowercase meets uppercase, like in thisSentence?

JavaScript how to split conjoining string on UpperCase and LowerCase Characters

How do I alternatively uppercase and lowercase characters in a string?

Scala how can I uppercase first character and lowercase others

How can I convert uppercase letters to lowercase in Notepad++

How can i convert uppercase in lowercase inside a list?

How can i check if the file extension is uppercase or lowercase?

How do I make an list that can be read as either uppercase or lowercase

How to detect uppercase and lowercase characters in a string using pointers

how to compare two string regardless of lowercase and uppercase using angular js

convert uppercase letter to lowercase letter

How do I lowercase any string then capitalize only the first letter of the word with Javascript?

How can i make first letter of all words in a string uppercase recursively?

How can I rename a directory name replacing the first letter of each word in the name string to uppercase?

How can I check if a string is all uppercase in JavaScript?

How can I test if a string for a function call using regex in JavaScript?