Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression for numeric range 0000 to 9999

I need a regular expression for a text field in my asp.net website

which should lie in between

0000 to 9999

it is not be

0 to 9999


2 Answers

I think this could be:

^\d{4}$

Don't forget to escape it if you are using c#

string numReg = @"^\d{4}$";
like image 160
Jhonny D. Cano -Leftware- Avatar answered Mar 21 '26 20:03

Jhonny D. Cano -Leftware-


Along with the other answers, you could also try this.

^[0-9]{4}$
like image 27
Scott Ivey Avatar answered Mar 21 '26 21:03

Scott Ivey