'Reg-Expression to validate Indian Mobile Numbers staring with +919, +918, +917, +916, 919, 918, 917, 916, 0, 9, 8, 7, 6
Reg-Expression to validate Indian Mobile Numbers (+91, 91, 0) starting with 9, 8, 7, 6 and should be in the below formats:
- Just the number
8994455555
7994455555
6994455555
9994455555
99944 55555
99944-55555
999 445 5555
999-445-5555
- 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
- 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
- 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
Solution 1:[1]
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
((\+)?(91[\-\s]?)):(\+)?begin with a+sign (Not Compulsory) followed by(91[\-\s]?)gives91,91and91-(Not Compulsory).- or
|. (0[\-\s]?)?begin with a0(Not Compulsory).((([6-9]{1}\d{2})-?\s*?(\d{3})-?\s*?(\d{4}))Consider([6-9]{1}\d{2})-?\s*?, Indian Mobile Numbers begin with either6,7,8or9, followed by any 2-digits from0-9(\d{2}). Next it will be no-space, (-) or space (Not Compulsory) - followed by next 3-digits from0-9(\d{3}). Which is again followed by no-space, (-) or space (Not Compulsory). Finally, 4-digits from0-9(\d{3}) --> Format563-898-5647,563 898 5647or5638985647- or
|. (([6-9]{1}\d{4})-?\s*?(\d{5}))Consider([6-9]{1}\d{4})-?\s*?, Indian Mobile Numbers, followed by any 4-digits from0-9(\d{4}). Next it will be no-space, (-) or space (Not Compulsory) - followed by next 3-digits from0-9(\d{5}). --> Format56389-85647,56389 85647or5638985647.
Solution 2:[2]
try the following regex:
^(\+91[\-\s]?)?[0]?(91)?[789]\d{9}$
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Daly Hachicha |
