I am trying to build a regex for following rules
- No characters – only numbers are allowed to enter
- Numbers must contain not less than 8 digits
- Numbers and combinations, starting as follows should not be allowed:
- [3.1] – Any number starting with 0 (zero) and with 1 (one);
- [3.2] – Numbers starting with 20, 21, 22, 23, 24, 25, 26, and 27.
I am able to achieve regex for points 1, 2 and 3.1 like this
^[2-9]{1}[0-9]{7,}$
But I am not able to find solution for point 3.2
This is one of the options I started with, this regex matches the string that must start with 20, 21, 22, 23, 24, 25, 26, or 27.
^([2][0-7])[2-9]{1}[0-9]{7,}$
I just have to find the negation of this first condition.
Please help!
>Solution :
Rather than trying to negate the 20-27 condition, just match numbers that start with 28 or 29 instead:
^(?:2[89]|[3-9]\d)\d{6,}$