I want to validate name and surname for my Ruby on Rails 3 application and so I have posted this question. Someone adviced me to read the Falsehoods Progra
The simple answer is, you cannot validate names and surnames other than to verify they are not null*. By filling in a form that asks for a name, somebody is declaring "this is my name", and if someone says "this is my name", you should believe them because they are the ultimate authority of what is their name.
* even then, it's perfectly valid for people to have a single name rather than two or three, and there has been one instance of an individual who didn't actually have a name. He gave himself a symbol instead.
If you have read that article, you have seen that it is not possible to validate a name, with or without regular expressions.
So don't even go there. If people want to call themselves Tarquin Fin-tim-lin-bin-whin-bim-lim-bus-stop-F'tang-F'tang-Olé-Biscuitbarrel (it has happened! see the section "Cultural references"), who are you to deny it to them?
The correct way to validate names is:
\pM
, \pZ
, nor \pC
; i.e., is neither one of the combining marks, separators, nor other (usually control) characters. A character class like [^\pM\pC\pZ]
should suffice.There: easy as can be. You will probably need Ruby 1.9 to do this properly, though.