0

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 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.