How to Validate Three-Part Names (First–Middle–Last) in a Text List Question?

Hello team, I am working with a roster question similar to the one in the World Bank MTF Energy Survey – Household Questionnaire, where we ask:

“Make a complete list of all individuals who normally live and eat their meals together in this household.”

The roster uses a list question to capture the names of household members.

I would like to validate each entered name to ensure it is in the format:

First Name, Middle Name, Last Name

Specifically, I need help implementing validation rules that will ensure:

  1. Exactly three names are entered (no more, no less).

  2. Initials are not allowed (e.g., “A. Juma” or “J K Lema” should fail).

  3. Each name must start with an uppercase letter, followed by lowercase letter.

I will appreciate your inputs.

Hi Jeff,

On your specific request, here are the three validation checks to be placed at the list question itself (self)— each kept separate so you can attach meaningful error/warning messages to help enumerators understand what went wrong.


1) Exactly three names entered

(First, Middle, Last)

self.All(x => x.Item2.Trim().Split(' ').Length == 3)


2) No initials allowed

(No single-letter parts; no dots; only alphabetic characters)

self.All(x =>
    x.Item2.Trim()
        .Split(' ')
        .All(p => p.Length >= 2 && p.All(char.IsLetter))
)


3) Each part must start with uppercase and continue in lowercase

self.All(x =>
    x.Item2.Trim()
        .Split(' ')
        .All(p =>
            System.Text.RegularExpressions.Regex.IsMatch(p, @"^[A-Z][a-z]+$")
        )
)

The first thing I’d always check in any list question like this is uniqueness of names, so that two members do not end up with identical entries. For example:

/* Use all items entered, remove any whitespace and put to upper */
self.Select(x =>
    System.Text.RegularExpressions.Regex.Replace(x.Item2, @"\s+", "")
        .ToUpper()
).Distinct().Count() == self.Count()


A small note: think carefully before enforcing very strict name-format rules.
In many surveys these requirements can become burdensome for enumerators, especially the upper/lowercase rule — this is something that can easily be cleaned during data processing. Enforcing too much structure during interview may slow the interview down or lead to unnecessary corrections. That’s at least my two cents :smiley:

Hope it helps.

Peter

This is very helpful. Thank you, I’ll keep your advice in mind as well.