Search code examples
phpregexvalidationunicodeletter

How to check that string contains letter in any language?


My current regex is /^[a-zA-Z]+( [a-zA-Z]+)*$/. It works for names like:

John Smith

Anyway, the site is international and name could be like this, for example:

Jānis Bērziņš

It's a valid name, but regex will fail to validate it because of ā, ē and š chars.

The one way would be to type all chars that are allowed, but then the list would be HUGE!

I'm looking for easier way to do that. Maybe black-list instead of white-list approach?

Thanks in any advice!


Solution

  • Use a regex in UTF-8 mode with the appropriate Unicode character propert(y/ies).