Reputation: 145
I tried this, but in this case, 11 and 12 are allowed too:
^[0-9]{10,13}$
I need just 10 or 13.
Upvotes: 0
Views: 3735
Reputation: 123458
You could use alternation (matches the regex before or after):
^[0-9]{10}|[0-9]{13}$
This would match 10 or 13 digits.
Upvotes: 4
Reputation: 12797
You can do also
^\d{10}(\d{3})?$
10 digits + optional 3 digits
Upvotes: 6