Indian Phone Number Regex for Java
/^(?:\+91[\s.-]?)?(?!09)([6-9][0-9]{9}|0[1-9][0-9]{1,2}[\s.-]?[0-9]{7,8})$/What this pattern does
This page provides a comprehensive, battle-tested regular expression for matching indian phone number, ported and verified for Java. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your Java project — whether you're validating in a Spring Boot controller, a Jakarta EE service, or a standalone utility class.
Java Implementation
// Indian Phone Number
// ReDoS-safe | RegexVault — Localization > Phone Numbers
import java.util.regex.Pattern;
public class IndianPhoneNumberValidator {
private static final Pattern PATTERN =
Pattern.compile("^(?:\\+91[\\s.-]?)?(?!09)([6-9][0-9]{9}|0[1-9][0-9]{1,2}[\\s.-]?[0-9]{7,8})$");
public static boolean validate(String input) {
return PATTERN.matcher(input).matches();
}
// Example
public static void main(String[] args) {
System.out.println(validate("+91 9876543210")); // true
}
}Test Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
+91 9876543210 | +91 5876543210 |
9876543210 | +91 98765432 |
+919876543210 | 98765432100 |
6789012345 | 0987654321 |
011-12345678 | — |
When to use this pattern
This pattern is drawn from the Localization > Phone Numbers category and carries a ReDoS-safe certification. That matters for Java developers because critical in Java applications since the JVM regex engine uses backtracking and is susceptible to ReDoS without careful pattern design. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.
Common Pitfalls
India has a complex telecom numbering plan. Numbers starting with 1, 2, 3, 4, or 5 are not currently assigned for mobile use but may be used for landlines. Validate via TRAI's number plan if precision is needed.
Technical Notes
Indian mobile numbers are 10 digits starting with 6-9 (5 is currently unassigned). Landlines include city code (011 for Delhi, 022 for Mumbai) + 7-8 digit local number. Country code is +91.
Have a pattern that belongs in the vault?
Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.
Submit a Pattern