Regular expression to match 10-14 digits

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

^[0-9]

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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).

Method 2

^d{10,14}$

regular-expressions.info

  • Character Classes or Character Sets

    d is short for [0-9]

  • Limiting Repetition

    The syntax is {min,max}, where min is a positive integer number indicating the minimum number of matches, and max is an integer equal to or greater than min indicating the maximum number of matches.


The limited repetition syntax also allows these:

^d{10,}$ // match at least 10 digits
^d{13}$  // match exactly 13 digits

Method 3

try this

@"^d{10,14}$"

d – matches a character that is a digit

This will help you

Method 4

If I understand your question correctly, this should work:

d{10,14}

Note:
As noted in the other answer.. ^d{10,14}$ to match the entire input


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x