How can I quickly validate if a string is alphabetic only, e.g
var str = "!";
alert(isLetter(str)); // false
var str = "a";
alert(isLetter(str)); // true
Edit : I would like to add parenthesis i.e () to an exception, so
var str = "(";
or
var str = ")";
should also return true.
Regular expression to require at least one letter, or paren, and only allow letters and paren:
Modify the regexp as needed:
/^[a-zA-Z()]*$/– also returns true for an empty string/^[a-zA-Z()]$/– only returns true for single characters./^[a-zA-Z() ]+$/– also allows spaces