stef
stef

Reputation: 27789

Simple regex that matches x or x+y

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

Answers (3)

vansimke
vansimke

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

devnull69
devnull69

Reputation: 16574

This one should do the trick

/^([1-9]|10)(\+([1-9]|10)){0,1}$/

Upvotes: 1

kevingessner
kevingessner

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

Related Questions