Regular expression for Iranian mobile phone numbers?

Viewed 16395

How can I validate mobile numbers with a regular expression? Iran Mobile phones have numeral system like this:

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

Some examples for prefixes:

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

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

18 Answers

How about this one ?

^(\+98?)?{?(0?9[0-9]{9,9}}?)$

working for:

09036565656

09151331685

09337829090

09136565655

09125151515

+989151671625

+9809152251148

check out the results here

in javascript you can use this code

let username = 09407422054
let checkMobile = username.match(/^0?9[0-9]{9}$/)

it will return

["9407422054", index: 0, input: "9407422054", groups: undefined]

the best regex pattern

(+?98|098|0|0098)?(9\d{9})

^(\+98|0)?9\d{9}$

Will match with numbers like +989123456789 and

^[0][9][0-9][0-9]{8,8}$

match with numbers like 09123456789

I used this for Iran Mobile and worked for Irancell , rightell and MCI 0935-0939 ,0912,0901,0910,0902,0903,...

 public static MobilePattern: string = '09[0-9]{9}$';

It's Simple. Iran TCI Phone in Any Format

Supports These Formats

+98217777777

98217777777

098217777777

0098217777777

217777777

0217777777

function IsIranPhone(phone) {
    if (phone == null || phone ==undifined) {
        return false;
    }
    return new RegExp("^((|0|98|098|0098|\\+98)[1-8][1-9][2-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])$").test(phone);
}

Using this code in C#

  public bool IsMobileValid(string mobile)
    {
        if (string.IsNullOrWhiteSpace(mobile))
            return false;
        if (Regex.IsMatch(mobile, @"(0|\+98)?([ ]|-|[()]){0,2}9[1|2|3|4]([ ]|-|[()]) 
             {0,2}(?:[0-9]([ ]|-|[()]){0,2}){8}"))
            return true;
        return false;
    }
//check phone number
function check_phone(number) {
    var regex = new RegExp('^(\\+98|0)?9\\d{9}$');
    var result = regex.test(number);

    return result;
}

$('#PhoneInputId').focusout(function () {
    var number = $('#crt-phone').val();
    if (!check_phone(number)) {
       your massage...
    } else {
       your massage...
    }
});

this is best answer, i tested all answers but this is easy and best

Related