RegEx to check for 3 or more consecutive occurrences of a character

I want to check the input line to check for the correct text.

and. I want users to be allowed to write alphanumeric characters, including period, comma, hyphen and parenthesis ()

b. However, I do not want users to enter NUMBER with three or more digits together. for example: 12 is allowed, but 185 is NOT.

with. I do not want users to enter strings like "............." or "----------" or "aaaaaaaaaaaaaa" or "bbbbbbbbb", etc.

Please suggest a regex for the same.

+5
source share
2 answers

You can use regex:

(?!.*(.)\1{2})^[a-zA-Z0-9.,()-]*$

lookahead (?!.*(.)\1{2}), , 3 .

^[a-zA-Z0-9.,()-]*$, , , , , , .

+1

regex libs : /(.)\1{2,}/

\1 -

0

All Articles