开发者

Javascript validation Problem

开发者 https://www.devze.com 2023-01-10 22:52 出处:网络
In my employee information page, i use the validation in the information page. In tha开发者_开发百科t javascript regular expression,

In my employee information page, i use the validation in the information page.

In tha开发者_开发百科t javascript regular expression,

var nameRegex = /^[(a-z)(A-Z)\s ]*$/;

This nameRegex match with my last and firstname.

} else if(!lastname.match(nameRegex)) {

For this one, special character are not allowed in last name. It restrict all the special character apart from brackets as ( ). Why it ignore the bracket? What is the reason for that. will you help me friends?


You put parenthesis in your expression. It should be more like:

/^[a-zA-Z\s]*$/

or

/^[A-Z\s]*$/i

(i means case insensitive)

If you put parenthesis inside a character class [], they don't have any special meaning but are taken literally. Btw \s matches all whitespace characters, so you don't have to include a literal whitespace.


Try this:

/^[A-Za-z()\s]*$/
0

精彩评论

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