Seeker
Seeker

Reputation: 1897

Regex for Full Name Field in Jquery Validation

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

Answers (2)

areeb
areeb

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

David Hedlund
David Hedlund

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

  • O'Brien
  • François
  • Linné
  • שְׂרוּ

Upvotes: 3

Related Questions