php - RegEx to check 3 or more consecutive occurrences of a character -
i want check input string validate proper text.
a. want users allow writer alphanumeric characters including period, comma, hyphen , round bracket ()
b. however, dont want users enter number 3 or more digits together. eg: 12 allowed while 185 not.
c. dont want users enter strings "............." or "----------" or "aaaaaaaaaaaaaa" or "bbbbbbbb" etc.
please suggest regular expression same.
you can use regex:
(?!.*(.)\1{2})^[a-za-z0-9.,()-]*$
it uses negative lookahead (?!.*(.)\1{2})
ensure there no group of 3 repetitions of of characters.
then uses regex ^[a-za-z0-9.,()-]*$
ensure string made of alphabets, numbers, period, comma, parenthesis , hyphen.
Comments
Post a Comment