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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -