How to check if string has no vowel after 4 consecutive chars

Viewed 2006

I want to check if a user is entering something close to a valid name. So if it's entered something like gbcvcvrt, I would want to validate it and mark this as not a real name. Something like theg+vowel should be validated as the right name.

On any length of string the code should detect four consecutive non vowel alphabets. I don't expect anyone's name to be rhythm by the way

Consider

$String = 'therhythm';

We can't check for the first four chars, we have to go through the entire string and check four any four consecutive non-vowel alphabets regardless of where on the string they are situated. That way we can validate $String as not valid even though the first five chars would validate it if we were checking the first four alphabets.

  • Should also not contain 3 consecutive vowels,
  • Should not contain numbers,
  • Non Alphabetic chars
4 Answers
Related