I am working on a regex to validate a string that,
- contains alphanumeric value
- does not contain identical characters more than 4 times in a row (like aaaaa or 222222)
- total length should be between 6 to 15
I am using the following regex, but it doesn't work for the input => String1bbbbb
/^(?=.*[a-z])(?=\S*[A-Z])(?=\S*[0-9])(?!.*[\w{4,}])[a-zA-Z0-9]{6,15}+$/i
if(preg_match('/^(?=.*[a-z])(?=\S*[A-Z])(?=\S*[0-9])(?!.*[\w{4,}])[a-zA-Z0-9]{6,15}+$/i', $string)) {
echo "Valid String";
} else {
echo "invalid String";
}
using negative look ahead to validate the identical characters like below
(?!.*[\w{4,}])
Any help would be appreciated.