I am trying to validate phone number but cannot.
My requirement is phone number consist only of digits and + (plus symbol). The + can be only the first character.
For example: +123456489
I am using this regular expression but it is not working:
/^\+(?:[0-9]??)$/
Thanks in advance.
I'd use this instead:
^\+?\d*$
Matches your + at the start, then any digit, dash, space, dot, or brackets.
See it in action: http://regex101.com/r/mS9gD7
If you only want to allow +
sign and that is only at the beginning of the number and does not want to allow any other characters or symbols other that the digits, then try the below regex:
var regEx = /^[+]?\d+$/;
regEx.test("+123345"); // this will be true
regEx.test("++123345"); // this will be false
regEx.test("1+23345"); // this will be false
regEx.test("111222"); // this will be true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With