Python Practice › RegEx Programs › Program 2
Validate Indian mobile numbers
Write a Python program to validate 10-digit Indian mobile numbers with an optional +91.
Output
9876543210 True +91 9123456789 True +91-8123456789 True 5123456789 False 98765 False
Approach
(\+91[\s-]?)?[6-9]\d{9}.
Solution
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.