Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

need a REGEX pattern to match

Tags:

.net

regex

need help with validating a 9-digit number.

CANNOT BE 
-----------
000000000
111111111
222222222
333333333
444444444
555555555
666666666
777777777
888888888
999999999

4-5 position(s) CANNOT BE 00 -- 123001234

6-9 position(s) CANNOT BE 00 -- 234550000

The nine numbers CANNOT BE sequential -- but only the following 4 four below, for the time being --

012345678
123456789
987654321
098765432

I had just managed to get the first piece done --

"^(?:(?!0+|1+|2+|3+|4+))\d{9}$"

Thanks a TON for the help friends.

like image 561
CocaCola Avatar asked Jan 29 '26 16:01

CocaCola


1 Answers

A single regex to validate all your rules may exist, but it will be much more easier, readable and maintainable if you write a validation rule (which can be a regex) for each of your criteria.

And as a more general comment, regex are usually great to check what a string IS, but they are not that good when it comes to check what a string IS NOT.

like image 143
Xavier Avatar answered Jan 31 '26 06:01

Xavier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!