Home > Software design >  Reg-Expression to validate Indian Mobile Numbers staring with 919, 918, 917, 916, 919, 918, 917,
Reg-Expression to validate Indian Mobile Numbers staring with 919, 918, 917, 916, 919, 918, 917,

Time:04-03

Reg-Expression to validate Indian Mobile Numbers ( 91, 91, 0) starting with 9, 8, 7, 6 and should be in the below formats:

  1. Just the number
8994455555
7994455555
6994455555
9994455555

99944 55555
99944-55555

999 445 5555
999-445-5555
  1. Starting with 91
 919994455555
 91 9994455555
 91-9994455555

 91999 445 5555
 91-999-445-5555
 91 999-445-5555
 91 999 445 5555

 9199944 55555
 91-99944-55555
 91 99944-55555
 91 99944 55555
  1. Starting with 91
919994455555
91 9994455555
91-9994455555

91999 445 5555
91-999-445-5555
91 999-445-5555
91 999 445 5555

9199944 55555
91-99944-55555
91 99944-55555
91 99944 55555
  1. Starting with 0
09994455555
0 9994455555
0-9994455555

0999 445 5555
0-999-445-5555
0 999-445-5555
0 999 445 5555

099944 55555
0-99944-55555
0 99944-55555
0 99944 55555

CodePudding user response:

Reg-Expression that supports all the above formats is

r'^((\ )?(91[\-\s]?))|(0[\-\s]?)?((([6-9]{1}\d{2})-?\s*?(\d{3})-?\s*?(\d{4}))|(([6-9]{1}\d{4})-?\s*?(\d{5})))$'

invalid formats:

54623987
56489 56489
563 589 6456
 91 563 898 5647
91 562563
91 5645555555
91 66555855575
0 55556 45654

CodePudding user response:

try the following regex:

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