Reputation: 135
I am trying to get a RegEx working for 0-100% including 0, but not as a leading number. EXAMPLE valid inputs would be 0, 10, 34, 100 and invalid would be 00, 01, 045, 000, or any number larger than 100.
I'm finding a lot of examples with 1-100 on here but not single 0, and my lack of understanding RegEx isn't helping me make the proper adjustments. Thanks for help.
Upvotes: 1
Views: 172
Reputation: 785661
You can use this regex:
^(?:\d|[1-9]\d|100)$
RegEx Breakup:
^
: Start(?:
: Start non-capturing group
\d
: match numbers from 0
to 9
|
: OR[1-9]\d
: match numbers from 10
to 99
|
: OR100
: match 100
)
: End non-capturing group$
: EndUpvotes: 6