Alex Rivera | Logout

Regular expression to match 10-14 digits

Asked 2010-04-24T05:20:03.940
12

I am using regular expressions for matching only digits, minimum 10 digits, maximum 14. I tried:

^[0-9]
Edit
Report

1 Answer

20

I'd give:

^\d{10,14}$

a shot.

I also like to offer extra solutions for RE engines that don't support all that PCRE stuff so, in a pinch, you could use:

^[0-9]{10,14}$

If you're RE engine is so primitive that it doesn't even allow specific repetitions, you'd have to revert to either some ugly hack like fully specifying the number of digits with alternate REs for 10 to 14 or, easier, just checking for:

^[0-9]*$

and ensuring the length was between 10 and 14.

But that won't be needed for this case (ASP.NET).

answered 2010-04-24T05:27:11.280

Your Answer