DEV Community

Discussion on: What's in a name (validation)?

Collapse
 
jillesvangurp profile image
Jilles van Gurp

Name input is something I've had to deal with on a few occasions. There are many ways to mess this up. I'd say the number 1 mistake is doing something custom/naieve here the worst of which is having a full name field only. It's a mistake every time and fixing that mistake is a pain in the ass.

That begs the question what the standard way is here. Well, for better or for worse we have a long tradition of putting name information in address books. This has led to a number of fields with specific, well understood meaning. It's not perfect, but people are used to using them, most third party systems have them, etc. If you look at e.g. the vcard standard, most address books in IOS, Android, Outlook, social media profiles, etc, you'll find that they tend to go for either the full set of these fields or the minimal subset of first and last name. This is not an accident. There are also fields like middle name, title/salutation. You can concatenate these to a full name field.

Whatever you do, don't simplify it to a single field called "full name". This has been a mistake every time I've seen it. It usually leads to expensive development efforts to fix it. It's usually the result of some UX designer going like "hmm wouldn't it be nice if I could eliminate some fields to simplify things in our super duper hipster UI". Great reflex but it ends in tears every time you actually need proper name metadata to e.g. send emails/letters/notifications, deal with 3rd party systems that also have names, CRM systems, etc.

In my experience, this always happens at some point at which point the full name field becomes a problem that needs fixing. I've been in more than one meeting where some idiot goes like "hey can't we just split the name on the first space or something". Nope, it doesn't work like that. You cannot recover a first name from a full name reliably for the reasons you state above.

Having just a full name means you don't actually care what the name is or addressing the user correctly. If you don't care about the name, why bother asking for it? If you do ask for it, do it properly and such that you don't create a huge mess down the road when you actually need proper name information.

When in doubt, first/last name is common enough that people understand what to put there. It fits most use cases and you can do cute things like "Dear firstName", or "Dear Mr./Mrs. lastName" in your communications. I can guarantee you this will come up whenever the story for sending user notifications comes on the board. People will put all sorts of crap in a full name field. It's an open invitation to just doing whatever for the user (and they do). Meaning this field is unusable for many use-cases that involve names. Including displaying them, using them in communications, dealing with 3rd party systems, etc. Shit in shit out. It's that simple.

Don't validate name fields other than requiring first/last name to be non blank. They should be UTF-8 encoded (seriously, stop using other encodings already). If somebody wants to put the unicode poo character in their name, let them. Their choice.

Whenever you need a full name, the algorithm is firstName + ' ' + lastName. Treat it like an output field only. If you have a non blank middleName, it goes in the middle. Everybody understands that first name comes before last name and that middle implies it comes after first but before last. It transcends cultures. It doesn't break user expectations to have these fields.
Most people understand what to put there; they've been conditioned for decades. In some cultures you put family name first. In some last. Some people have multiple first and last names separated by spaces.

Collapse
 
annelebas profile image
Anne Le Bas (she/her)

Can't comment on the coding complexities, but name order is not straightforward, as the name order section here shows. personal name followed by family name is a Western European/US convention. Large swathes of the cultures of the rest of the world do things differently. At least ask for given/family name and name order
if you are going to separate them. Nd the most important thing in the article - be clear that it is a deficiency of the coding not the person's name if it can't be done correctly.
en.m.wikipedia.org/wiki/Personal_n...