I use Clickatell to send SMSes to clients' mobile phones.
Is there a standardised regular expression for all valid mobile phone numbers, e.g. +27 123 4567? I'd roll my own, but I'm worried about missing an obscure, valid phone number format.
Specifically, ‹ ^ › matches at the beginning of the text, and ‹ $ › at the end. This ensures that the phone number regex does not match within longer text, such as 123-456-78901 .
/^([+]\d{2})? \d{10}$/ This is how this regex for mobile number is working.
Mobile Number validation criteria:The first digit should contain numbers between 6 to 9. The rest 9 digit can contain any number between 0 to 9. The mobile number can have 11 digits also by including 0 at the starting. The mobile number can be of 12 digits also by including 91 at the starting.
Validate a Phone Number Using a JavaScript Regex and HTML function validatePhoneNumber(input_str) { var re = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/; return re. test(input_str); } function validateForm(event) { var phone = document. getElementById('myform_phone').
After stripping all characters except '+' and digits from your input, this should do it:
^\+[1-9]{1}[0-9]{3,14}$
If you want to be more exact with the country codes see this question on List of phone number country codes
However, I would try to be not too strict with my validation. Users get very frustrated if they are told their valid numbers are not acceptable.
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