Validate Indian mobile numbers

EasyRegEx Programs · 2 of 20

Write a Python program to validate 10-digit Indian mobile numbers with an optional +91.

Advertisement
Output
9876543210       True
+91 9123456789   True
+91-8123456789   True
5123456789       False
98765            False

Approach

  1. (\+91[\s-]?)?[6-9]\d{9}.

Solution

Python
import re for n in ["9876543210", "+91 9123456789", "+91-8123456789", "5123456789", "98765"]:    print(n.ljust(16), bool(re.fullmatch(r"(\+91[\s-]?)?[6-9]\d{9}", n)))
Output
9876543210       True
+91 9123456789   True
+91-8123456789   True
5123456789       False
98765            False

Learn the concept

New to this topic? Read the lesson, then come back.

More regex programs

← All 20 RegEx Programs

Leave a Comment