Reputation: 40639
How can I validate a field only with upper case letters which are alphabetic. So, I want to match any word made of A-Z characters only.
Upvotes: 8
Views: 50152
Reputation: 30993
Try this:
if (<value>.match(/^[A-Z]*$/)) {
// action if is all uppercase (no lower case and number)
} else {
// else
}
here is a fiddle: http://jsfiddle.net/WWhLD/
Upvotes: 1
Reputation: 7579
Try something like this for the javascript validation:
if (value.match(/^[A-Z]*$/)) {
// matches
} else {
// doesn't match
}
And for validation on the server side in php:
if (preg_match("/^[A-Z]*$/", $value)) {
// matches
} else {
// doesn't match
}
It's always a good idea to do an additional server side check, since javascript checks can be easily bypassed.
Upvotes: 15
Reputation: 141829
var str = 'ALPHA';
if(/^[A-Z]*$/.test(str))
alert('Passed');
else
alert('Failed');
Upvotes: 5