r/regex • u/Postive_Coder • 1d ago
Regex to match a 12-digit Aadhaar number without matching Indian phone numbers with 91 country code?
I'm trying to write a regular expression to detect or extract 12-digit Aadhaar numbers from text, without accidentally matching Indian phone numbers that include the 91 country code (12 digits total: 91 + 10-digit mobile number). [1, 2]
Context & Constraints:
- Aadhaar format: 12 digits (sometimes formatted with spaces or hyphens like
XXXX XXXX XXXXorXXXX-XXXX-XXXX), first digit is2–9(not0or1). - Phone number conflict: Indian mobile numbers are 10 digits (typically starting with
6–9), so with91(or+91/091) prepended, they can look like a 12-digit number starting with91. - Use case:
[Mention if you are doing full-string validation vs. finding/extracting inside a larger block of text or logs, and your programming language/regex engine, e.g., Python, JavaScript, PCRE.][1, 2]
What I need help with:
- How can I avoid false positives from
91-prefixed 12-digit phone numbers (e.g.,919876543210or+91 9876543210)? - Are there edge cases with spaces, hyphens, or word/digit boundaries I should watch out for?
- Should I pair the regex with Verhoeff checksum validation in code rather than relying on regex alone?
