Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to validate names

Tags:

regex

php

I would like to create a regex which validates a name of a person. These should be allowed:

  • Letters (uppercase and lowercase)
  • -
  • spaces

This is pretty easy to create a regex for. The problem is that some people also use special characters in their names. For example, assume a user named gûnther or François. There are a lot of characters like û and ç available and it's hard to list all of these.

Is there an easy way to check for correct human names?

like image 410
Bv202 Avatar asked Dec 05 '22 23:12

Bv202


1 Answers

Is there an easy way to check for correct human names?

This has been discussed several times. I'm fairly certain that the only thing that people can agree on is that in order to exist a name cannot be a empty string, thus:

^.+$

(Yes, I am aware that this is probably not what OP is looking for. I'm just summarizing earlier Q&As.)

like image 139
jensgram Avatar answered Dec 07 '22 22:12

jensgram