Regular expression for Iran mobile numbers?

how can I check a user's mobile phone number using regular expression. Iran mobile phone has a digital system as follows:

091- --- ----
093[1-9] --- ----

Some sample prefixes:

0913894----
0937405----
0935673---- 
0912112----

Source: http://en.wikipedia.org/wiki/Telephone_numbers_in_Iran

+5
source share
10 answers

Best Regular Expression for Detecting Iranian Mobile Phones

I am sure this is the best regular expression for detecting Iranian mobile number.

(0|\+98)?([ ]|-|[()]){0,2}9[1|2|3|4]([ ]|-|[()]){0,2}(?:[0-9]([ ]|-|[()]){0,2}){8}

use in javascript

var
mobileReg = /(0|\+98)?([ ]|-|[()]){0,2}9[1|2|3|4]([ ]|-|[()]){0,2}(?:[0-9]([ ]|-|[()]){0,2}){8}/ig,
junkReg = /[^\d]/ig,
persinNum = [/۰/gi,/۱/gi,/۲/gi,/۳/gi,/۴/gi,/۵/gi,/۶/gi,/۷/gi,/۸/gi,/۹/gi],
num2en = function (str){
  for(var i=0;i<10;i++){
    str=str.replace(persinNum[i],i);
  }
  return str;
},
getMobiles = function(str){
  var mobiles = num2en(str+'').match(mobileReg) || [];
  mobiles.forEach(function(value,index,arr){
    arr[index]=value.replace(junkReg,'');
    arr[index][0]==='0' || (arr[index]='0'+arr[index]);
  });
  return mobiles;
};

// test
console.log(getMobiles("jafang 0 91 2 (123) 45-67 jafang or +۹۸ (۹۱۵) ۸۰ ۸۰ ۸۸۸"));

support all parameters like these

912 123 4567
912 1234 567
912-123-4567
912 (123) 4567
9 1 2 1 2 3 4 5 6 7
9 -1 (2 12))3 45-6 7
and all with +98 or 0
+989121234567
09121234567
9121234567

or even persian numbers

+۹۸ (۹۱۵) ۸۰ ۸۰ ۸۸۸

091x 092x 093x 094x

: https://gist.github.com/AliMD/6439187

+8

^09\d{2}\s*?\d{3}\s*?\d{4}$

( 4-3-4).

+3

wiki http://en.wikipedia.org/wiki/Telephone_numbers_in_Iran#Mobile_phones, :

091x-xxx-xxxx
0931-xxx-xxxx
0932-xxx-xxxx
0933-xxx-xxxx
0934-xxx-xxxx
0935-xxx-xxxx
0936-xxx-xxxx
0937-xxx-xxxx
0938-xxx-xxxx
0939-xxx-xxxx

(the specific sequence 09) (1 followed by 0-9 OR 3 followed by 1-9) (7 digits) 

, ,

09 (1 [0-9] | 3 [1-9]) [0-9]{7} <-- spaces added for emphasis
09(1[0-9]|3[1-9])[0-9]{7} <-- actual regex

((..|..) OR, [0-9]{7} 7 ,...)

:

09(1[0-9]|3[1-9])-?[0-9]{3}-?[0-9]{4}

+3

- . :

^09[1|2|3][0-9]{8}$
//091 for Hamrahe-Aval Operator
//092 for Rightel Operator
//093 for Irancel Oprator 

#, :

public static bool IsValidMobileNumber(this string input)
{
    const string pattern = @"^09[1|2|3][0-9]{8}$";
    Regex reg = new Regex(pattern);
    return reg.IsMatch(input);
}

:

If(!txtMobileNumber.Text.IsValidMobileNumber())
{
  throw new Exception("Mobile number is not in valid format !");
}
+3

, reg ex

^09\d{9}$, , 09, 9

\d ^ 09 [0-9] {9} $

Regex objNotNaturalPattern=new Regex("[^09[0-9]{9}]");

objNotNaturalPattern.IsMatch(yourPhoneNumber);

, .

+1

\A09\d{9}

0
string sPattern = "^09[-.\\s]?\\d{2}[-.\\s]?\\d{3}[-.\\s]?\\d{4}$";

if (System.Text.RegularExpressions.Regex.IsMatch(stringToMatch, sPattern)){
   System.Console.WriteLine("Phone Number is valid");
} else {
   System.Console.WriteLine("Phone Number is invalid");
}

, 09, , , , 2 ..

ex: 09001234567 09 11 123 4567 09-01-123-4567 09.01.123.4567 0900.000.0000 0900-000-0000 0900.000-0000 ..

0

/^ ({(09) ([1-3]) {2} - ([0-9]) {7,7}}?) $/

:

- 0913-1234567
- 0933-1234567

:

- 0944-1234567
- 0955-1234567

'-',

0

^ 09 (1\d | 3 [1-9]) -\d {3} -\d {4} $

- , :

( )

09

1 , 3 0

- 3

- 4

( , )

... , ( ):

        List<string> possible = new List<string> { "091-555-8888", 
"0915-888-4444", 
"0930-885-8844", 
"0955-888-8842" };

        string regex = @"09(1\d|3[1-9])-\d{3}-\d{4}$";

        foreach (string number in possible)
        {
            Console.WriteLine("{0} is{1} an Iranian number", number, Regex.IsMatch(number, regex) ? "" : " not");
        }
0

0903 ---- Irancell, :

^(0|\+98)?([ ]|,|-|[()]){0,2}9[0|1|2|3|4]([ ]|,|-|[()]){0,3}(?:[0-9]([ ]|,|-|[()]){0,2}){8}$
0

All Articles