darksoul90
darksoul90

Reputation: 145

Regular expression for 10 or 13 digits

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

Answers (2)

devnull
devnull

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

Ulugbek Umirov
Ulugbek Umirov

Reputation: 12797

You can do also

^\d{10}(\d{3})?$

10 digits + optional 3 digits

Upvotes: 6

Related Questions