Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
96
rated 0 times [  103] [ 7]  / answers: 1 / hits: 33435  / 13 Years ago, fri, june 3, 2011, 12:00:00

I want to create a regular expression where only numbers are allowed with max length 9 and no minimum length. I came up with d{9}[0-9] but it isn't working.


More From » regex

 Answers
118

You're close. Try this:



^d{0,9}$


The ^ and $ match the beginning and the end of the text, respectively. d{0,9} matches anywhere in the string, so d0000 would pass because it would match the 0000 even though there is a d in it, which I don't think you want. That's why they ^$ should be in there.


[#91878] Thursday, June 2, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jensenb

Total Points: 634
Total Questions: 102
Total Answers: 102

Location: Bosnia and Herzegovina
Member since Thu, Jun 24, 2021
3 Years ago
;