I am trying to find a regular expression for mobile phones that gives me 07550440002 or +4475504400003 up to 20 characters, i.e. I want a regular expression that may + or may not and then a whole number. I have ^(\+?[0-9])$ but I keep on getting the error message unexpected quantifier.
This happens when I try and run the follwowing code –
if (!$(textBox).val().match(RestrictionRegularExpressions.MOBILEPHONE)) {
Where RestrictionRegularExpressions.MOBILEPHONE is set the above reg expression
I don’t think it likes the \+.
This is using JQuery/Javascript
Any help would be greatly appreciated.
Thanks
I believe that the given regular expression does not work because the backslash needs to be escaped as well. Using a double backslash should do the trick.
The following regular expression worked for me:
Which I tested using this page on W3Schools web-page: http://www.w3schools.com/js/tryit.asp?filename=tryjs_regexp_test. It accepts 0 to 20 numbers prefixed by an optional ‘+’ sign.
Hope that helps