1

I want to make an Angularjs regex validation that allow all alphabets, numbers, space and following special characters ! ' " & - ( )

2
  • 2
    Try ng-pattern="/^[a-zA-Z0-9\s!'\x22&()-]*$/" Commented Aug 22, 2017 at 9:09
  • 1
    I posted with an explanation below. Commented Aug 22, 2017 at 9:16

1 Answer 1

3

You may use

ng-pattern="/^[a-zA-Z0-9\s!'\x22&()-]*$/"

Details

  • ^ - start of string
  • [a-zA-Z0-9\s!'\x22&()-]* - 0 or more:
    • a-zA-Z - ASCII letters
    • 0-9 - ASCII digits
    • \s - whitespaces
    • !'\x22&()- - !, ', " (\x22 matches "), &, (, ) or - (the hyphen must be at the end/start of the character class or escaped to denote a literal -)
  • $ - end of string.
Sign up to request clarification or add additional context in comments.

2 Comments

This regex doesn't seem to be complete. There are symbols missing, such as @.
@cst1992: See the requirement: all alphabets, numbers, space and following special characters ! ' " & - ( ). No mentioning of @.

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.