I'm trying to write a regular expression to check names for invalid entries. Basically I'm trying to eliminate people entering random junk as their name. I know I can't completely eliminate it but I'm trying to make it a little harder at the very least. Here is what I have so far. It works fine I'm wondering if there's a way to improve this.

[b-df-hj-np-tv-z]{5,}|[aeiou]{4,}|([a-z])(?=([a-z]*\1){3,})|([ ])(?=([a-z]*\3){2,})|[0-9]+

1 Answer 1


First off, there is an error: You have the part [b- duplicated at the beginning.

The first section matches five successive consonants, which is possbile. Examples for German words (although not names) with up to eight successive consonants: http://www.duden.de/sprachwissen/sprachratgeber/die-woerter-mit-den-meisten-aufeinanderfolgenden-konsonanten

The same goes for four successive vowels. Again examples in German with up to five: http://www.duden.de/sprachwissen/sprachratgeber/die-woerter-mit-den-meisten-aufeinanderfolgenden-vokalen

Then the next one basically matches when a specific letter is repeated three times anywhere in the name and that can't be terribly rare.

And finally one that only allows two spaces, thus names consisting of three words. And I've come across plenty of names in my live with more than three words.

Finally a technical note: If you really want to do this, you need to do it server side. JavaScript validation is trivially easy to circumvent.

  • \$\begingroup\$ I will only be matching this against names and first name and last name are in two separate fields so they will be checked individually. \$\endgroup\$
    – archon
    Mar 27, 2014 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.