3
Answers

Regex & Regular Expressions

Ashley Jackson

Ashley Jackson

18y
2.3k
1
I'm trying to use regular expressions to validate a string before converting it to a number.  The string must be all numeric (obviously) and exactly 8 digits long.  I have tried all of the follow regular expressions:

"[0-9]{8}"
"\d{8}"
"[0-9]{8}$"
"[0-9]{8,8}"



The problem I am having is that the expression returns a Match.Success as long as the string is at least 8 digits long.  If it is 9 ot returns OK, and I want it to return false.

Any Ideas????

Thanks Ash..
Answers (3)