views:

13

answers:

1

I'm using the following rule in jquery validate to make a name field, called nombre, only accept letters.

jQuery.validator.addMethod("nombre", function(value, element, param) {



   return jQuery.trim(value).match(new RegExp("^(?:" + param + ")$"));





});



$("#nombre").rules("add", { nombre: "[a-zA-Z]+"})

I want the regex to accept something like

Polly Jean Harvey

or

P.J. Harvey 

as valid names, (they are currently rejected). How can I add space between words and periods to the regex? Of course, I still want to reject blank names.

+1  A: 

You can use [a-zA-Z. ]+ as a regex.

It will accept spaces and dots.

But You can have different names such as "Pierre-Henry de la Brancardière". And this sort of name would be invalid.

As javascript doesn't support unicode with \p I would suggest you to do a blacklist of invalid characters instead of a whitelist.

Colin Hebert