help with regular expressions [closed]
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this questionthis is my goal numbers from the three digits to 9 digits. for example
Valid options
175
1.250
14.365
145.985
1.562.745
17.487.984
999.999.999
Now this is the regular expression that i develop
/^\d{1,3}\.\d{1,3}\.\d{1,3}$/
My problem it's that this is accepting this values
176.57.117 <---- this is not valid value
176.257.7 <---- this is not valid value
176.257.17 <---- this is not valid value
Thanks for your help
UPDATE I'm trying to make a regular expression that validates positive natural numbers from three digits to 9 digits and separates the thousand unit and the million unit with a point
/^\d{1,3}(\.\d{3}(\.\d{3})?)?$/
What you really want is 1 to 3 digits possibly followed by 1 or 2 additional sets of three digits. Your original reg-ex just said "3 sets of 1-3 digits" which isn't really what you want. It also would have failed to accept your first several valid examples since they had less than three sets of digits.
Just split the string for .
and then check string length ... in each of array indexes (i think it will be more self explaining than regexp)
精彩评论