Regex Template Error Throw Lexer AngularJS

I get Lexer error when using ng-patternfor input element

My regular expression is to check the phone numbers, and at the input it looks like 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 then Angular yells at me and gives me this error:

Error: [$parse:lexerr] Lexer Error: Unexpected next character  at columns 1-1 [\] in expression [(\(?([0-9]{3})\)?)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})].

Now I see how angry he is at mine \. However, I do not know how to write a regular expression without avoiding this. The funny thing is that the test really works, and it checks correctly, but I hate throwing an error for no reason.

Any ideas as to why this is happening?

thanks

+4
source share
1 answer

\ , ngPattern new RegExp('stringhere'), , .

+5

Source: https://habr.com/ru/post/1624500/


All Articles