views:

30

answers:

2

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

In that 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?

+2  A: 

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.

Felix Kling
A: 

Try this:

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