Reputation: 27789
I'm trying to validate an input field to accept x OR x+y where x and y are whole numbers from 1-10. Which regular expression matches this? This is to be used with custom jQuery validation.
Examples
Upvotes: 2
Views: 129
Reputation: 974
Try this: /^([1-9]||10){1}(+([1-9]|10)){0,1}$/
Excellent reference site: http://www.regular-expressions.info/reference.html
Upvotes: 0
Reputation: 18995
This should do it (assuming your "1-10" was inclusive of both ends):
^([1-9]|10)(\+([1-9]|10))?$
http://rentzsch.github.com/JSRegexTeststand/ is your friend here.
Upvotes: 9