62

I want regular expression for indian mobile numbers which consists of 10 digits.
The numbers which should match start with 9 or 8 or 7.

For example:

9882223456
8976785768
7986576783

It should not match the numbers starting with 1 to 6 or 0.

Unihedron
  • 10,902
  • 13
  • 62
  • 72
anshul
  • 631
  • 1
  • 6
  • 4
  • Does this answer your question? [Regular Expression Validation For Indian Phone Number and Mobile number](https://stackoverflow.com/questions/18351553/regular-expression-validation-for-indian-phone-number-and-mobile-number) – gnat Feb 12 '20 at 09:09

18 Answers18

161

^[789]\d{9}$ should do the trick.

^     #Match the beginning of the string
[789] #Match a 7, 8 or 9
\d    #Match a digit (0-9 and anything else that is a "digit" in the regex engine)
{9}   #Repeat the previous "\d" 9 times (9 digits)
$     #Match the end of the string

UPDATE

Some Telecom operators in india introduced new mobile number series which starts with digit 6.

for that use:

^[6-9]\d{9}$
Sumit Joshi
  • 1,047
  • 1
  • 14
  • 23
eldarerathis
  • 35,455
  • 10
  • 90
  • 93
  • I have deleted my previous comment because I found it to be incorrect. The `\d` will apparently match any numeral known by the regex engine no matter what the current culture is. That is, it will match both latin, arabic and punjabi numerals etc. – Martin Liversage Sep 28 '10 at 14:14
  • the regex returns true for all 7,8,9 as well. Can these cases be handled in a regex? – Rajesh Jul 03 '15 at 05:53
  • Bro @eldarerathis there is big flow in this. It also validates numbers having more than 10 digit. Basically our(because i am also using this) regex finds a valid number placed anywhere in a string.Like this 123456`9897969594`12345 . This can be solved by additionally checking length of string containing number. I would be happy if you give alternative regex. – Ravinder Payal Apr 17 '16 at 06:27
  • 3
    @RavinderPayal This regex is anchored with `^` and `$` to ensure it only matches across the entire string. It does not match strings longer than 10 characters, nor will it match fewer. Whatever regex engine or method you are using is causing it. [Here's your string in Rubular](http://rubular.com/r/NBvMyEO9AA) - it only matches the 10 character one. – eldarerathis Apr 17 '16 at 21:05
  • @eldarerathis thanks bro i missed `^` sign thank again and +1 – Ravinder Payal Apr 18 '16 at 04:38
  • Please check below answer for the indian mobile number validation – webx Sep 28 '16 at 13:06
  • What if I have to add a condition that 0s (zeros) should not be appearing more than 8 times how to go about with this? – Ibrahim Quraish Apr 18 '17 at 07:55
  • This won't validate `9999999999` – Noopur Phalak Jan 20 '18 at 07:35
  • @NoopurPhalak ? Of course it will. [Here's a demonstration](https://regex101.com/r/COfW8D/1). Why wouldn't it match `9999999999`? – eldarerathis Jan 20 '18 at 19:34
  • @eldarerathis Sorry, my bad, what I meant to say was, it should not match `9999999999` or any mobile numbers with only one number repeated ten times. – Noopur Phalak Jan 22 '18 at 06:25
  • @NoopurPhalak Ah, I see. IMO regex is going to be tough for that kind of check, but you are correct. It will accept a string where all digits are the same. – eldarerathis Jan 22 '18 at 20:42
  • @eldarerathis This should work `^(?!(\d)\1{9})[7,8,9]\d{9}$`. This will include mobile numbers where all digits are same. – Noopur Phalak Jan 24 '18 at 03:51
  • Some Telecom operators in india introduced new mobile number series which starts with digit 6. for that use: `^[6-9]\d{9}$` – Sumit Joshi Mar 05 '18 at 08:29
  • It is not working. Could You please checkout my snippet ? https://jsfiddle.net/uiexp/4o0j8k9h/3/ @eldarerathis – appsntech Jan 28 '19 at 15:28
55
^(?:(?:\+|0{0,2})91(\s*[\-]\s*)?|[0]?)?[789]\d{9}$

Hi, This is regex for indian local mobile number validation and for Indian international .

starting with 9,8,7 you can add more as well.

you can test it using https://regex101.com/

Valid number are.

9883443344
09883443344
919883443344
0919883443344
+919883443344
+91-9883443344
0091-9883443344
+91 -9883443344
+91- 9883443344
+91 - 9883443344
0091 - 9883443344

webx
  • 987
  • 7
  • 11
10

Here you go :)

^[7-9][0-9]{9}$
Lasse Espeholt
  • 17,622
  • 5
  • 63
  • 99
  • it should not match `9999999999` or any mobile numbers with only one number repeated ten times. The above regex with match it. – Noopur Phalak Jan 22 '18 at 06:28
9

This Worked for me

^(?:(?:\+|0{0,2})91(\s*[\ -]\s*)?|[0]?)?[789]\d{9}|(\d[ -]?){10}\d$

Valid Scenarios:

+91-9883443344
9883443344
09883443344
919883443344
0919883443344
+919883443344
+91-9883443344
0091-9883443344
+91 -9883443344
+91- 9883443344
+91 - 9883443344
0091 - 9883443344
7856128945
9998564723
022-24130000
080 25478965
0416-2565478
08172-268032
04512-895612
02162-240000
+91 9883443344
022-24141414

Invalid Scenarios:

WAQU9876567892
ABCD9876541212
0226-895623124
6589451235
0924645236
0222-895612
098-8956124
022-2413184
Vikas
  • 121
  • 1
  • 2
  • 1
    I used your regex in javascript but I have to remove ^ and $ symbol. And also have to \\ inplace of single \. Can you explain me why ^ and $ is used for? – Pankaj Vavadiya Jun 13 '16 at 07:41
  • @Pankaj ^ - Used to check beginning of the string $ - Used to check end of the string In many programming languages, there are some special characters which are processed by the compiler before the regex. For example: To match the string D:\test, the regex would be written as "D\:\\test" You can get more information on this [link](http://www.regular-expressions.info/characters.html) – Vikas Jul 21 '16 at 09:42
  • @VikasKitawat: Yes vikas I got the things. I found all from https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions for javascript – Pankaj Vavadiya Jul 21 '16 at 12:50
  • @Vikas In following case, it should return false validateMobile('99876543210') returns true – VINIT CHURI Nov 27 '21 at 03:09
9

You may use this

/^(?:(?:\+|0{0,2})91(\s*|[\-])?|[0]?)?([6789]\d{2}([ -]?)\d{3}([ -]?)\d{4})$/

Valid Entries:

6856438922
7856128945
8945562713
9998564723
+91-9883443344
09883443344
919883443344
0919883443344
+919883443344
+91-9883443344
0091-9883443344
+91 9883443344
+91-785-612-8945
+91 999 856 4723

Invalid Entries:

WAQU9876567892
ABCD9876541212
0226-895623124
0924645236
0222-895612
098-8956124
022-2413184

Validate it at https://regex101.com/

abhijithvijayan
  • 835
  • 12
  • 17
  • 1
    its very common for phone numbers to be stored with the international code and therefore cut and paste jobs in forms will be better served by this pattern. – Aurovrata May 04 '21 at 03:55
7

To reiterate the other answers with some additional info about what is a digit:

new Regex("^[7-9][0-9]{9}$")

Will match phone numbers written using roman numerals.

new Regex(@"^[7-9]\d{9}$", RegexOptions.ECMAScript)

Will match the same as the previous regex. When RegexOptions.ECMAScript is specified \d matches any roman numeral.

new Regex(@"^[7-9]\d{9}$")

Will match phone numbers written using any numerals for the last 9 digits.

The difference is that the first two patterns will only match phone numbers like 9123456789 while the third pattern also will match phone numbers like 9੧੨੩੪੫੬੭੮੯.

So you can use \d to match native numerals. However, if you want to limit the match for native numerals to only some (like 7-9) you need an additional step. For punjabi (India) to be able to match ੯੧੨੩੪੫੬੭੮੯ you can do it like this:

CultureInfo.GetCultureInfo("pa-IN").NumberFormat.NativeDigits.Skip(7).Take(3)

This will return the native numerals for 7-9. You can then join them together to form a "culture aware" regular expression for the digits 7-9.

Martin Liversage
  • 104,481
  • 22
  • 209
  • 256
5

i have used this regex in my projects and this works fine.

pattern="[6-9]{1}[0-9]{9}"
2
"^((0091)|(\+91)|0?)[789]{1}\d{9}$";

Is also a valid expression. You can precede it with either 0091,+91 or 0 and is optional.

For more details with code sample, refer to my blog.

Unihedron
  • 10,902
  • 13
  • 62
  • 72
Gokuldas
  • 39
  • 4
2

This is worked for me using JAVA script for chrome extension.

document.body.innerHTML = myFunction();
function myFunction()
{
    var phonedef = new RegExp("(?:(?:\\+|0{0,2})91(\\s*[\\- ]\\s*)?|[0 ]?)?[789]\\d{9}|(\\d[ -]?){10}\\d", "g");

    var str = document.body.innerHTML; 
    var res = str.replace(phonedef, function myFunction(x){return "<a href='tel:"+x.replace( /(\s|-)/g, "")+"'>"+x+"</a>";});

    return res;
}

This covers following numbers pattern

9883443344
8888564723 
7856128945

09883443344 
0 9883443344 
0-9883443344

919883443344 
91 8834433441 
91-9883443344 
91 -9883443344 
91- 9883443344 
91 - 9883443344 
91 -9883443344

+917878525200 
+91 8834433441 
+91-9883443344 
+91 -9883443344 
+91- 9883443344 
+91 - 9883443344 
+91 -9883443344

0919883443344 
0091-7779015989 
0091 - 8834433440 
022-24130000 
080 25478965 
0416-2565478 
08172-268032 
04512-895612 
02162-240000 
022-24141414 
079-22892350
Pankaj Vavadiya
  • 481
  • 7
  • 15
2

Swift 4

 - Mobile Number Validation [starting with 7,8,9]

     func validate(value: String) -> Bool {
                let PHONE_REGEX = "^[7-9][0-9]{9}$";
                let phoneTest = NSPredicate(format: "SELF MATCHES %@", PHONE_REGEX)
                let result =  phoneTest.evaluate(with: value)
                return result
            }

       if validate(value: value) {
                print("True")
            }
Vishal Vaghasiya
  • 4,618
  • 3
  • 29
  • 40
1
var PHONE_REGEXP = /^[789]\d{9}$/;

this works for ng-pattern in angularjs or in javascript or any js framework

Shahzad Barkati
  • 2,532
  • 6
  • 25
  • 33
Rajesh
  • 642
  • 2
  • 7
  • 14
1
/(((^[\+,0][9][1])(((\s[0-9]{7,10})|(\S[0-9]{7,10}))|([-]\S[0-9]{7,10})))|((^[\+,0][2]{2,2})((\S[0-9]{7,8})|((([-])[0-9]{7,8})|(\s[0-9]{7,8})))))|(((^[6,7,8,9][0-9]{9,9}))|(^[0,\+](([9][1)|[6,7,8,9]))[0-9]{8,9}))/gm

I don't know if there is a simple expression for this but I have created this REGEX that validates all possible Indian numbers that contains (0 or +) then (91 or 22 (since I needed it for Maharashtra and second thing is that India have too many STD codes)) or directly searches for numbers starting with 6,7,8,9 that have/don't have a 0 in front of it .

(/[regex]/gm) is a trial for multi-line search you can remove it(//gm) if it fails to work/gives error.

Feel free to try it at regex101. My Project of this REGEX is here .

OMKAR AGRAWAL
  • 128
  • 1
  • 9
1

for Indian mobile number use this reg expression

^(?:(?:\+|0{0,2})91(\s*[\ -]\s*)?|[0]?)?[789]\d{9}|(\d[ -]?){9}\d$
Apurv
  • 21
  • 5
0

Here's a regex designed to match typical phone numbers:

^(((\+?\(91\))|0|((00|\+)?91))-?)?[7-9]\d{9}$
cf-
  • 8,598
  • 9
  • 36
  • 58
d-coder
  • 1,180
  • 1
  • 11
  • 17
0

If you are trying to get multiple mobile numbers in the same text (re.findall) then you should probably use the following. It's basically on the same lines as the ones that are already mentioned but it also has special look behind and look ahead assertions so that we don't pick a mobile number immediately preceded or immediately followed by a digit. I've also added 0? just before capturing the actual mobile number to handle special cases where people prepend 0 to the mobile number.

(?<!\d)(?:\+91|91)?\W*(?P<mobile>[789]\d{9})(?!\d)

You may try it on pythex.org!

shad0w_wa1k3r
  • 12,955
  • 8
  • 67
  • 90
0

Solutions(^[789]\d{9}$ or ^[789][0-9]{9}$) told by others have a one big flow (If that is used for form validation) It also validates numbers having more than 10 digit. Basically our(Because I was also using this) regex finds a valid number placed anywhere in a string.Like this 123456989796959412345 .

The problem can be solved by additionally checking length of string containing number. Like this if(regex.test(value) && value.length==10)/****do whatever*****/alert("Valid Number");

Note:- According to my tests , the regex.test(value) tests only roman numerals for this expression ^[789]\d{9}$ in both firefox(mozilla) and chrome(webkit)

Ravinder Payal
  • 2,884
  • 31
  • 40
0

In Swift

 extension String {
    var isPhoneNumber: Bool {
      let PHONE_REGEX = "^[7-9][0-9]{9}$";
      let phoneTest = NSPredicate(format: "SELF MATCHES %@", PHONE_REGEX)
      let result =  phoneTest.evaluate(with: self)
      return result
   }
}
Sourabh Kumbhar
  • 1,034
  • 14
  • 12
0

For Laravel 5.4+

'mobile_number_1' => 'required|numeric|min:0|regex:/^[789]\d{9}$/' should do the trick

Akash Sethi
  • 184
  • 1
  • 4
  • 15