Regular Expression Validation For Indian Phone Number and Mobile number
Asked Answered
A

14

28

I want to validate Indian phone numbers as well as mobile numbers. The format of the phone number and mobile number is as follows:

For land Line number

03595-259506
03592 245902
03598245785

For mobile number

9775876662
0 9754845789
0-9778545896
+91 9456211568
91 9857842356
919578965389

I would like the regular expression in one regex. I have tried the following regex but it is not working properly.

{^\+?[0-9-]+$}
Alodie answered 21/8, 2013 at 7:40 Comment(0)
Q
26

For land Line Number

03595-259506
03592 245902
03598245785

you can use this

\d{5}([- ]*)\d{6}

NEW for all ;)

OLD: ((\+*)(0*|(0 )*|(0-)*|(91 )*)(\d{12}+|\d{10}+))|\d{5}([- ]*)\d{6}
NEW: ((\+*)((0[ -]*)*|((91 )*))((\d{12})+|(\d{10})+))|\d{5}([- ]*)\d{6}

9775876662
0 9754845789
0-9778545896
+91 9456211568
91 9857842356
919578965389

03595-259506
03592 245902
03598245785

this site is useful for me, and maby for you .;)http://gskinner.com/RegExr/

Quarterage answered 21/8, 2013 at 7:46 Comment(1)
When I am using this regex in JS, it showing error " Invalid regular expression: /^((+*)((0[ -]*)*|((91 )*))((d{12})+|(d{10})+))|d{5}([- ]*)d{6}$/: Nothing to repeat " .can you please help me to resolve it.Brennen
D
18

Use the following regex

^(\+91[\-\s]?)?[0]?(91)?[789]\d{9}$

This will support the following formats:

  1. 8880344456
  2. +918880344456
  3. +91 8880344456
  4. +91-8880344456
  5. 08880344456
  6. 918880344456
Derte answered 9/2, 2016 at 8:2 Comment(1)
@Ajay update regex to : ^(\+91[\-\s]?)?(\91[\-\s]?)?[0]?(91)?[123456789]\d{9}$) for validating 91-8883044456 if required in your caseTragacanth
C
10

This works really fine:

\+?\d[\d -]{8,12}\d

Matches:

03598245785
9775876662
0 9754845789
0-9778545896
+91 9456211568
91 9857842356
919578965389
987-98723-9898
+91 98780 98802
06421223054
9934-05-4851
WAQU9876567892
ABCD9876541212
98723-98765

Does NOT match:

2343
234-8700
1 234 765
Curst answered 12/1, 2015 at 15:16 Comment(1)
This regex is accepting these no also: (@5094 10574Wigan
K
7

for mobile number:

const re = /^[6-9]{1}[0-9]{9}$/;
Kelly answered 26/5, 2021 at 12:45 Comment(2)
This seems like a useful addition relative to the accepted answer, which is only for landline formats. But why is this preferred over e.g., @parth’s answer, which claims to support both landline and mobile formats?Espionage
Also, it’d be useful to add the test cases you evaluated this against, as other answers have done, to help demonstrate the scope of formats it will cover.Espionage
C
5

I use the following for one of my python project

Regex

(\+91)?(-)?\s*?(91)?\s*?(\d{3})-?\s*?(\d{3})-?\s*?(\d{4})

Python usage

re.search(re.compile(r'(\+91)?(-)?\s*?(91)?\s*?(\d{3})-?\s*?(\d{3})-?\s*?(\d{4})'), text_to_search).group()

Explanation

(\+91)? // optionally match '+91'
(91)?   // optionally match '91'
-?      // optionally match '-'
\s*?    // optionally match whitespace
(\d{3}) // compulsory match 3 digits
(\d{4}) // compulsory match 4 digits

Tested & works for

9992223333
+91 9992223333
91 9992223333
91999 222 3333
+91999 222 3333
+91 999-222-3333
+91 999 222 3333
91 999 222 3333
999 222 3333
+919992223333
Centromere answered 16/1, 2020 at 18:57 Comment(1)
update your answer.. (\+91)?(-)?\s*?(91)?\s*?([6-9]{1}\d{2})-?\s*?(\d{3})-?\s*?(\d{4}).. Indian numbers start with either 6,7,8 or 9..Derogate
I
4

For both mobile & fixed numbers: (?:\s+|)((0|(?:(\+|)91))(?:\s|-)*(?:(?:\d(?:\s|-)*\d{9})|(?:\d{2}(?:\s|-)*\d{8})|(?:\d{3}(?:\s|-)*\d{7}))|\d{10})(?:\s+|)

Explaination:

(?:\s+|)                    // leading spaces
((0|(?:(\+|)91))            // prefixed 0, 91 or +91
(?:\s|-)*                   // connecting space or dash (-)
(?:(?:\d(?:\s|-)*\d{9})|    // 1 digit STD code & number with connecting space or dash
(?:\d{2}(?:\s|-)*\d{8})|    // 2 digit STD code & number with connecting space or dash
(?:\d{3}(?:\s|-)*\d{7})|    // 3 digit STD code & number with connecting space or dash
\d{10})                     // plain 10 digit number
(?:\s+|)                    // trailing spaces

I've tested it on following text

9775876662
0 9754845789
0-9778545896
+91 9456211568
91 9857842356
919578965389

0359-2595065
0352 2459025
03598245785
07912345678
01123456789
sdasdcsd
+919898101353
dasvsd0 
+91 dacsdvsad
davsdvasd

0112776654
Irritating answered 24/5, 2016 at 11:53 Comment(0)
W
0

All mobile numbers in India start with 9, 8, 7 or 6. Now, there is a chance that you are not bothering about the prefixes (+91 or 0). If this is your scenario, then you can take the help from the website regextester.com or you can use r'^(+91[-\s]?)?[0]?(91)?[789]\d{9}$'

And if you want to validate the Phone number with prefixes(+91 or 0) then use : r'^[6-9]\d{9}$'.

Wear answered 6/3, 2019 at 11:47 Comment(0)
G
0

You can use regular expression like this.

/^[(]+\ ++\d{2}[)]+[^0]+\d{9}/

Gagliano answered 14/11, 2019 at 11:56 Comment(1)
This is matching ((((((((( 12)))))))))))))))))))))))))*$ù^^<q!§à@çè"é """123456789jsqfh khe alkjlkjrh erj kjhklerjaht lekjarhtlkjrt not sure it is a valid phone number.Kinglet
C
0

For Indian Mobile Numbers

Regular Expression to validate 11 or 12 (starting with 0 or 91) digit number

String regx = "(0/91)?[7-9][0-9]{9}";

String mobileNumber = "09756432848";

check 

if(mobileNumber.matches(regx)){
   "VALID MOBILE NUMBER"
}else{
   "INVALID MOBILE NUMBER"
}

You can check for 10 digit mobile number by removing "(0/91)?" from the regular expression i.e. regx

Contractive answered 15/4, 2020 at 18:27 Comment(1)
Now, Mobile numbers can start with digit "6".Spondylitis
G
0

you can implement following regex regex = '^[6-9][0-9]{9}$'

Gruchot answered 23/7, 2020 at 5:44 Comment(0)
B
0
r'\+?(91?|0?)[\-\s]?[3-9]\d{3}[\-\s]?\d{6}$'

explanation

  1. +? # Start with plus sign or not
  2. (91?|0?) # Followed by 91 or 0 or none of them
  3. [-\s]? # Followed by either - or space, or none of them
  4. [3-9] # followed by any number from 3 between 9
  5. \d{3} # followed by any three digits
  6. \d{6} # followed by any six digits
  7. $ # specify string should stop at that point
Beelzebub answered 4/2, 2023 at 13:31 Comment(0)
C
-1

You Can Use Regex Like This:

   ^[0-9\-\(\)\, ]+$
Cow answered 29/8, 2013 at 8:49 Comment(0)
S
-1

All Landline Numbers and Mobile Number

^[\d]{2,4}[- ]?[\d]{3}[- ]?[\d]{3,5}|([0])?(\+\d{1,2}[- ]?)?[789]{1}\d{9}$

Supernal answered 31/8, 2017 at 11:28 Comment(0)
S
-2
var phonereg = /^(\+\d{1,3}[- ]?)?\d{10}$/;
Sooksoon answered 22/6, 2017 at 10:20 Comment(2)
Please explain the regex for future visitors.Upbraid
Can you please explain your code? it's not self explanatoryStilton

© 2022 - 2025 — McMap. All rights reserved.