Hi, I need to check by Regex expression if 9 or 14 digits are typed. The expression "\d{9}|\d{14}" seems to be not working properly, what's wrong ?
+1
A:
It depends on the variant of regular expression syntax you are using as to whether the length {n-m} operator is supported. Which one are you using?
James Keesey
2009-12-28 19:57:15
+4
A:
This regex should work.
^(\d{9}|\d{14})$
Could you post the piece of code you're using and tell us what language are you using? If you're using regex chances are that you have a string, and I'm sure your language has something to count string length.
EDIT:
as Rubens Farias pointed out in comments maybe ^...$ is needed because your regex would match any number with more than 9 digit as that number has a substring with a 9 digit long number.
Anyway check if you can do it with your language's string's methods/functions
Andrea Ambu
2009-12-28 19:57:23
maybe you should to use ^..$, to match entire input text.
Rubens Farias
2009-12-28 19:59:36
You're right, thanks!
Andrea Ambu
2009-12-28 22:29:58