ng-pattern for alphanumeric and all special symbol characters

Nithin picture Nithin · Jun 21, 2017 · Viewed 8.5k times · Source

In input, I need to allow alphanumeric and all special symbol character. I am using the following pattern. Unfortunatelly, it is not working.

ng-pattern="/^[ A-Za-z0-9_@./#$=!%^)(]:*;?/\,}{'|<>[&+-]*$/"

Answer

Mistalis picture Mistalis · Jun 21, 2017

You missed to escape all the characters that should be excaped with \. The following may work:

ng-pattern="/^[A-Za-z0-9_@.#$=!%^)(\]:\*;\?\/\,}{'\|<>\[&\+-]*$/"

Note that it could be simplified to:

ng-pattern="/^[A-z\d_@.#$=!%^)(\]:\*;\?\/\,}{'\|<>\[&\+-]*$/"

Test it on regex101