Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegEx for valid international mobile phone number [duplicate]

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.

like image 983
Petrus Theron Avatar asked Feb 21 '11 13:02

Petrus Theron


People also ask

How do you write regex in a phone number?

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 .

How can I check mobile number in regex?

/^([+]\d{2})? \d{10}$/ This is how this regex for mobile number is working.

How do you validate a phone number using a validator?

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.

How can I validate a phone number in JavaScript?

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').


1 Answers

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.

like image 80
Jannie Theunissen Avatar answered Sep 28 '22 05:09

Jannie Theunissen