Check if first letter of word is a capital letter

James J picture James J · Dec 1, 2011 · Viewed 84.2k times · Source

Is it possible in JavaScript to find out if the first letter of a word is a capital letter?

Answer

Gabriele Petrioli picture Gabriele Petrioli · Dec 1, 2011
var word = "Someword";
console.log( word[0] === word[0].toUpperCase() );

or

var word = "Someword";
console.log( /[A-Z]/.test( word[0]) );

or

var word = "Someword";
console.log( /^[A-Z]/.test( word) );

See toUpperCase() and test()