7

I need to validate mobile number. My need:

  1. The number may start with +8801 or 8801 or 01
  2. The next number can be 1 or 5 or 6 or 7 or 8 or 9
  3. Then there have exact 8 digit.

How can i write the regular expression using this conditions ?

the mobile numbers I tried

+8801811419556
01811419556
8801711419556
01611419556
8801511419556
  • 3
    Update your question with your code what you tried already. – Garfield Feb 26 '13 at 11:57
  • 8 digit mobile number??? – Shurmajee Feb 26 '13 at 12:00
  • A word of caution - regular expressions often aren't the easiest things to read even for seasoned programmers. Ask yourself the question: If the criteria changed, would you be comfortable making further changes? – Robbie Dee Feb 26 '13 at 12:06
  • @Shurmajee Actually the number is 11 digit long. All number start with 01. Then next 1 digit varies from operator to operator. Then the next 8 digit provided by operator. – Emdadul Sawon Jun 14 '16 at 06:10

7 Answers7

30

Should be pretty simple:

^(?:\+?88)?01[15-9]\d{8}$
  • ^ - From start of the string
  • (?:\+?88)? - optional 88, which may begin in +
  • 01 - mandatory 01
  • [15-9] - "1 or 5 or 6 or 7 or 8 or 9"
  • \d{8} - 8 digits
  • $ - end of the string

Working example: http://rubular.com/r/BvnSXDOYF8

Update 2020

As BTRC approved 2 new prefixes, 013 for Grameenphone and 014 for Banglalink, updated expression for now:

^(?:\+?88)?01[13-9]\d{8}$
Ratul
  • 302
  • 6
  • 20
Kobi
  • 135,331
  • 41
  • 252
  • 292
  • Yeah, yours looks better :) – kjetilh Feb 26 '13 at 12:08
  • 008801812596824 This mobile number is valid or not by using your example Please check and reply me using your given link http://rubular.com/r/BvnSXDOYF8 – Majbah Habib Sep 16 '18 at 04:45
  • @MajbahHabib - The question does not ask for numbers starting with `00`, so no. You can relatively easily change the pattern, for example, assuming `00` is an international access code: `^(?:(?:\+|00)?88)?01[15-9]\d{8}$` – Kobi Sep 16 '18 at 05:17
3

You may use either one of given regular expression to validate Bangladeshi mobile number.

Solution 1:

/(^(\+88|0088)?(01){1}[56789]{1}(\d){8})$/

Robi, Grameen Phone, Banglalink, Airtel and Teletalk operator mobile no are allowed.

Solution 2:

 /(^(\+8801|8801|01|008801))[1|5-9]{1}(\d){8}$/

Citycell, Robi, Grameen Phone, Banglalink, Airtel and Teletalk operator mobile no are allowed.

Allowed mobile number pattern

+8801812598624

008801812598624

01812598624

01712598624

01919598624

01672598624

01512598624

................

.................

Majbah Habib
  • 8,058
  • 3
  • 36
  • 38
1

Use the following regular expression and test it if you want on following site quickly

regex pal

[8]*01[15-9]\d{8}

K D
  • 5,889
  • 1
  • 23
  • 35
1

I know, that question was asked long time ago, but i assume that @G. M. Nazmul Hossain want to validate mobile number againt chosen country. I show you, how to do it with free library libphonenumber from Google. It's available for Java, C++ and Javascript, but there're also fork for PHP and, i believe, other languages.

+880 tells me that it's country code for Bangladesh. Let's try to validate example numbers with following code in Javascript:

String bdNumberStr = "8801711419556"
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
try {
    //BD is default country code for Bangladesh (used for number without 880 at the begginning)
    PhoneNumber bdNumberProto = phoneUtil.parse(bdNumberStr, "BD");
} catch (NumberParseException e) {
    System.err.println("NumberParseException was thrown: " + e.toString());
}
boolean isValid = phoneUtil.isValidNumber(bdNumberProto); // returns true

That code will handle also numbers with spaces in it (for example "880 17 11 41 95 56"), or even with 00880 at the beggininng (+ is sometimes replaced with 00).

Try it out yourself on demo page. Validates all of provided examples and even more.

Paweł Tomkiel
  • 1,974
  • 2
  • 21
  • 39
  • Thanks for the help. This is nice but it shows "8801311419556" and "8801411419556" as valid number But these two format are invalid mobile number. – G. M. Nazmul Hossain Mar 03 '15 at 04:19
  • @G. M. Nazmul Hossain - Are you sure, they aren't valid? You can fill bug on libphonenumber page for it: https://github.com/googlei18n/libphonenumber/issues . Google's building DB all over the world, so they would've missed something ;) – Paweł Tomkiel Mar 03 '15 at 07:45
0

Have a look at libphonenumber at: https://code.google.com/p/libphonenumber/

wwadge
  • 3,506
  • 1
  • 19
  • 28
0

Bangladeshi phone number (Citycell, Robi, Grameen Phone, Banglalink, Airtel and Teletalk operators) validation by using regular expression :

$pattern = '/(^(\+8801|8801|01|008801))[1-9]{1}(\d){8}$/';
$BangladeshiPhoneNo = "+8801840001417";

if(preg_match($pattern, $BangladeshiPhoneNo)){
    echo "It is a valid Bangladeshi phone number;
}
Hasib Kamal Chowdhury
  • 2,476
  • 26
  • 28
0
**Laravel Bangladeshi Phone No validation for (Citycell, Robi, Grameen Phone, Banglalink, Airtel and Teletalk) and start with +88/88 then 01 then 356789 then 8 digit**  



public function rules()
        {
            return [

                'mobile' => 'sometimes|regex:/^(?:\+?88)?01[35-9]\d{8}$/',

            ];
        }

        public function messages()
        {

                'mobile.regex' => 'Mobile no should be bd standard',
            ];
        }
Jasim Juwel
  • 736
  • 8
  • 19