开发者

Javascript validation Problem

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜