AbdulAziz
AbdulAziz

Reputation: 6278

Regex for digits from 0 to 16 digits Only in ASP.net

I have a text field that is the user choose to enter data in it, it must be digits and must be less than or equal to 16 digits (Not more than that).

I have regular expression for digits,

ValidationExpression="^\d{10}$"

which is be exactly 10 digits. But how to modify it for my scenario?

I am embarrassed by such a simple question, but I got confused. If it is a duplicate question or somebody asked similar question, please let me know.

Note: I need the regex for ASP.net

Upvotes: 0

Views: 2589

Answers (2)

Mark Reed
Mark Reed

Reputation: 95242

The curly-brace quantifier is {min,max}, so {0,16} will do for your case.

Upvotes: 2

Martin Ender
Martin Ender

Reputation: 44259

Here is a good tutorial.

^\d{0,16}$

Note, that in .NET, \d can also match any Unicode character that represents a digit (see here). If you really just want the ASCII digits, use

^[0-9]{0,16}$

(Since I am not sure how you would set RegexOptions if that is possible at all in your case.)

Upvotes: 3

Related Questions