Skip to content

Instantly share code, notes, and snippets.

@Akkuma
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akkuma/efd96c2033bbfbb5e8d9 to your computer and use it in GitHub Desktop.
Save Akkuma/efd96c2033bbfbb5e8d9 to your computer and use it in GitHub Desktop.
Simple JavaScript functions to check if a string is capitalized
//Assumes that a string is made up of only letters
function isCapitalized(str) {
var char = str[0];
return char.toUpperCase() == char;
}
//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