How can you check if the first charactère of letter is uppercase ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can you check if the first charactère of letter is uppercase ?

i need to to create a form and contrôle the last name and first name to be all characters and stats with capital letters ? with javascript

7th Oct 2021, 10:02 PM
Tamim Hmizi
Tamim Hmizi - avatar
3 Answers
+ 1
Tamim Hmizi it might not be necessary to check for capitalization. You could simply enforce the rule like this: name = name.charAt(0).toUpperCase() + name.substring(1) EDIT: I overlooked that you require JS to enforce only alphabetic characters along with capitalization. I think regex would be useful. This link appears to handle both requirements: https://stackoverflow.com/questions/36536495/capitalized-words-with-regular-expression
8th Oct 2021, 4:42 AM
Brian
Brian - avatar
0
Martin Taylor you are right, but he can check for numbers and other special character before and if it dont start with number or any of this, check for upper case.
8th Oct 2021, 9:54 AM
PanicS
PanicS - avatar
- 1
anyString.charAt(0) === anyString.charAt(0).toUpperCase() You need to compare your string with upperCased string. If it is same than it start with upperCase letter. CharAt is used to check letter.
7th Oct 2021, 10:20 PM
PanicS
PanicS - avatar