I am searching for a regular expression that matches any string that is:
- A number which is greater than zero
- The number has at least one digit
- No more than 12 digits
I tried this one without success:
^[1-9][0-9]*{1,12}$ I am searching for a regular expression that matches any string that is:
I tried this one without success:
^[1-9][0-9]*{1,12}$ The problem with the regular expression
^[1-9][0-9]*{1,12}$ is the star * used together with {1,12} as the star *means any number of repetitions of the previous symbol whereas {1,12} means one to twelve repetitions - so the star * and {a,b} don't mix and must be used exclusively, not together.
Use ^[1-9]\d{0,11}$, which checks for a non-zero digit followed by zero to 11 digits.
Your regex had a quantifier * after the second character class, which would allow zero or more occurrence of a digit (which can be more than 11 digits). Also the quantifier {1,12} sets the minimum occurrence of preceding pattern as 1 and maximum occurrence as 12. So you had to avoid the * and set minimum and maximum as 0 and 11 respectively, since there was already a pattern for single digit.
^[1-9][0-9]{0,11}$
Start with a single digit between 1-9, then have 0 to 11 occurrences of a digit between 0-9