Search code examples
angularjsregexng-pattern

ng-pattern for alphanumeric and all special symbol characters


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_@./#$=!%^)(]:*;?/\,}{'|<>[&+-]*$/"

Solution

  • 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