+ 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
3 Antworten
+ 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
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.
- 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.