javascript - Regex Pattern Throwing a Lexer Error AngularJS -
i'm getting lexer error when using ng-pattern on input element
my regex test phone-numbers , on input looks this:
<input type="text" class="phone" ng-pattern="(\(?([0-9]{3})\)?)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})" placeholder="phone number" ng-model="contactformvm.contact.phone" required /> and angular yells @ me , gives me error:
error: [$parse:lexerr] lexer error: unexpected next character @ columns 1-1 [\] in expression [(\(?([0-9]{3})\)?)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})]. now can see it's getting angry \. don't know how write regex without escaping that. funny thing is, test works , validate correctly, hate throwing error nothing.
any ideas why happening?
thanks
you need escape \ in string because ngpattern takes string , wraps in new regexp('stringhere') requires escape character.
Comments
Post a Comment