Currently I have:
[A-Za-z0-9._%+-]
This matches any string that contains letters, numbers, and certain special chars (._%+-
)
How can I change this so that it won't match a string that contains the special chars consecutively?
For example, I want it to match:
foo.bar+test
and foo.+bar
and +foo.
But not:
foo..bar+test
or foo.bar++test
or foo.bar++
If your tool/language supports look aheads, try:
^(?!.*([._%+-])\1)[A-Za-z0-9._%+-]+$
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