UmaShankar
UmaShankar

Reputation: 223

regex / ng-pattern to accept certain characters

I'm using Angular's form validation with ng-pattern to validate a username with Special Charter

ng-pattern="/^[a-z]+@+[a-z]*$/"

My problem is that is limited to only one type of Special Charter to be placed at required place.

I would like this to support any of the special characters we use in alphabets

Upvotes: 4

Views: 8989

Answers (2)

nivas
nivas

Reputation: 53

/^[a-zA-Z0-9/&quot&quot\\\]\[:;|=,+*?<>]+$/

allows: characters, digits and " / \ [ ] : ; | = , + * ? <>

Upvotes: 0

Jossef Harush Kadouri
Jossef Harush Kadouri

Reputation: 34257

It's not clear of what you define a Special Character, therefore assuming by your example that @ is a Special Character.

For example, if you want to support the characters @, ! and #, you will modify the regular expression like this:

ng-pattern="/^[a-z]+[@+!+#][a-z]*$/"

demo: http://plnkr.co/edit/cIjpI9LAJKgs1MvZmBJv?p=preview

Upvotes: 1

Related Questions