Last active
August 29, 2015 14:21
-
-
Save Akkuma/efd96c2033bbfbb5e8d9 to your computer and use it in GitHub Desktop.
Simple JavaScript functions to check if a string is capitalized
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Assumes that a string is made up of only letters | |
function isCapitalized(str) { | |
var char = str[0]; | |
return char.toUpperCase() == char; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Assumes nothing and can handle numbers and symbols | |
function isCapitalized(str) { | |
var rex = /^[A-Z]/ | |
return rex.test(str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment