开发者

regex for admitting blank spaces between words in a name in jquery validate

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 Jea开发者_如何学Cn 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜