Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anyone know a regular expression to validate MSISDN-format mobile numbers?

Does anyone know a regular expression to validate MSISDN-format mobile numbers?

I looked into a solution posted at http://charlvn.blogspot.com/2010/06/msisdn-regular-expressions.html but I think that's not a generic solution.

I'm looking for a validation regex that could validate any MSISDN-standard mobile number. http://en.wikipedia.org/wiki/MSISDN

Secondly, I'm looking for the means to check whether a valid MSISDN mobile number is from a specific country, like "31628000000" is a number from the netherlands, because it starts with the netnumber "31".

I'm going to implement the validating part in Python.

Thanks in advance!

like image 706
Dirk Avatar asked Jan 26 '11 19:01

Dirk


People also ask

How can I check mobile number in regex?

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

What is Msisdn used for?

On a cellular network, MSISDN (Mobile Station Integrated Services Digital Network) is the phone number which identifies a device during calls or data sessions. It performs a crucial function in ensuring secure connectivity between the different components within an IoT network.


2 Answers

This should do -- I'm not sure how much more generic you can get:

/^[1-9][0-9]{10,14}$/

To check a number to belong to a particular country, modify the pattern to preface the country code, and then adjust the remaining digits to match:

/^(873[1-9][0-9]{7,11}|91[1-9][0-9]{8,12})$/    #  India
/^46[1-9][0-9]{8,12}$/                          # Sweden
like image 169
Ether Avatar answered Sep 18 '22 03:09

Ether


  /^[1-9][0-9]{10,14}$/

The shortest international phone number is only 7 digits long, e.g. +247 2468.

  /^[1-9]\d{6,14}$/
like image 44
g1smd Avatar answered Sep 19 '22 03:09

g1smd