I have a requirement for regex - starting with a number and then can have letter numbers and special characters -_.\\s+ for hyphen, dot, underscore and space, etc. My other important requirement is that the length of the number is to be between 5 and 30 (inclusive) BUT it should not be 10 or 12 characters in length. I have prepared a regex as below:
^[0-9][a-zA-Z0-9-_.\\\s+]{5,30}$
I understand that the above regex regulates length between 5 and 30 characters BUT how do I restrict it NOT to have 10 or 12 characters length.
Please help.
BUT how do I restrict it NOT to have 10 or 12 characters length.
You could insert a negative lookahead at the start of the pattern to not expect 10 or 12 characters: (?!.{10}$|.{12}$).
The whole pattern would then be:
^(?!.{10}$|.{12}$)[0-9][a-zA-Z0-9-_.\\\s+]{5,30}$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With