Mouss Mouss - 8 months ago 48
AngularJS Question

Regex not working in angular JS

I am trying to build a custom regex for phone number validation, basically I allow any string longer than 10 character and that can contain only those characters : any number, "+", ".", "(", ")", "-" and white space.

Here is my regex :

var myRegex = new RegExp('^[0-9|\+|\.|\(|\)|\-|\s]{10,}$');

I don't know why this regex is not matching "01234567 89" or "01234567-89", I have tested it on a regex validator online and it is supposed to work.

I have plunkered my issue :


Change your regex to this to match your regex validator online example:

var myRegex = new RegExp(/^[0-9|\+|\.|\(|\)|\-|\s]{10,}$/);