javascriptangularjsregexng-pattern

Angular ng-pattern regex not working


I'm trying to create a validation for an angular input field which accepts only the a-zA-Z0-9 characters and special characters ".”(full stop), "_" (underscore), "@"(at sign)

I can't seem to get the hang of it.

I tried:

ng-pattern="/[a-zA-Z0-9_@.]+/"

requirement:


Solution

  • The ng-pattern should be as follows:

    ng-pattern="/^[a-zA-Z0-9_@.]+$/" 
    

    See demo here: http://plnkr.co/edit/ElBuuxGilBbC9fdA2n0P?p=preview