Skip to content

Instantly share code, notes, and snippets.

@stgogm
Last active March 14, 2019 16:01
Show Gist options
  • Save stgogm/32b54c4a5d00e73dedb2 to your computer and use it in GitHub Desktop.
Save stgogm/32b54c4a5d00e73dedb2 to your computer and use it in GitHub Desktop.
Person's name RegExp
/^([a-z\u00C0-\u02AB'´`]{1,}\.?\s?)([a-z\u00C0-\u02AB'´`]?\.?\s?)+$/i
@stgogm
Copy link
Author

stgogm commented Apr 27, 2017

Validates "real" person names (please see https://stackoverflow.com/questions/9445334/javascript-regex-valid-name).

These will be valid

  • O
  • Justine
  • Danny
  • Li Huang Wu
  • Cevahir Özgür
  • Yiğit Aydın
  • Finlay Þunor Boivin
  • Josué Mikko Norris
  • Tatiana Zlata Zdravkov
  • Ariadna Eliisabet O'Taidhg
  • sergej lisette rijnders
  • BRIANA NORMINA HAUPT
  • BihOtZ AmON PavLOv
  • Eoghan Murdo Stanek
  • Filimena J. Van Der Veen
  • D. Blair Wallace

These will be invalid

@frank331
Copy link

frank331 commented Mar 14, 2019

Hi, your regex worked pretty well for me amongst others and thus I wanted to thank you; I only have one problem, how can I avoid a single quote character (') to pass the regex?

-Edit:
I've done some research since I'm not so experienced with regex and I think I solved some problems for me with this modified version:
/^((?!.*[\u00D7\u00F7\u01C0-\u01C3])[a-z\u00C0-\u02AF´]{1,}\s?)((?!.*[\u00D7\u00F7\u01C0-\u01C3])[a-z\u00C0-\u02AF'´]?\s?)+$/i;
I have excluded the special caracters × ÷ ǀ ǁ ǂ ǃ that where inside the range of unicode 00C0-02AB, I've extended the latter range until 02AF to match the end of the unicode group and I've removed the single quote character form the first word (in this way I've resolved the case of a single quote passing the regex but for someone may not be good because it blocks the names starting with a single quote).
Regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment