Reputation: 1897
i have following method of Jquery Validation:
jQuery.validator.addMethod("alpha", function(value, element) {
return this.optional(element) || value == value.match(/^[a-zA-Z]+$/);
},"Only Characters Allowed.");
Now i am having problem that if i add a space between my name words it gives me error can anyone tell me what will be the Regex for checking a name which may have character inputs of A-Z,a-Z and also a space.
Upvotes: 0
Views: 19192
Reputation: 422
$("#ValuationName").bind("keypress", function (event) {
if (event.charCode!=0) {
var regex = new RegExp("^[a-zA-Z ]+$");
var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
if (!regex.test(key)) {
event.preventDefault();
return false;
}
}
});
Try This
Upvotes: 1
Reputation: 129792
Full names aren't regular. I would advise against validating any more than checking that it's not empty.
Different names in different cultures can look very different. There are heaps of special characters that aren't included in your pattern, that could very well exist in a name. Even quite common ones.
Consider
Upvotes: 3