I am trying to validate whether user is entering mobile number correctly. For this I have written the following regex which seems to be buggy. Mobile number can Optionally start with + can have Optional spaces, round brackets, hyphens ( - ). It cannot contain any alphabets or any other character.
jQuery.validator.addMethod("mobileNumber", function(value,element) {
return this.optional(element) || /(?:([+]))?[0-9]*/.test(value);
}, "Please enter a valid Contact Number");
Following inputs should match,
+1-222
(+1) 222
+1222
2222
02-222
But these shouldn't match.
1+222
AAA
AA12
2.2.2
How should I write the regex for above criteria?
Thanks.