- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to test if a letter in a string is uppercase or lowercase using javascript?
To test if a letter in a string is uppercase or lowercase using javascript, you can simply convert the char to its respective case and see the result.
Example
function checkCase(ch) { if (!isNaN(ch * 1)){ return 'ch is numeric'; } else { if (ch == ch.toUpperCase()) { return 'upper case'; } if (ch == ch.toLowerCase()){ return 'lower case'; } } } console.log(checkCase('a')) console.log(checkCase('A')) console.log(checkCase('1'))
Output
This will give the output −
lower case upper case ch is numeric
Advertisements