My question is NOT similiar to Regular expression to match numbers between 1-5000, because I have something else to check (no range, leading and no leading zeroes, etc.).
I have the following RegEx in an input check:
^[0-9]{1,4}$ This works for digits with 1-4 length.
Unfortunately I have to allow only these combinations:
- One digit numbers 1-9 (no leading zeroes)
- or two digits numbers 10-30 (no leading zeroes)
- or four digits numbers 0001-9999 (with leading zeroes).
What RegEx do I need?
|. Something like^([0-9]{1,4}|foo|bar)$, where foo is two digits numbers 10-30 (no leading zeroes), and bar is four digits numbers 0001-9999 (with leading zeroes). If you could write the regex you've got, you can write those -- the|operator is all you're missing.^([1-9][0-9]?|[0-9]{4})$. I guess you need to skip the numbers from100to999altogether, right? And does10-30range is just an example, and you want the 2-digit numbers from10to99or really only up to30only?^([1-9]|[12][0-9]|30|[0-9]{4})$