Number of any word name with Regex

Hi All,
I am trying to fix my beneficiary name with regex. I need to collect some names. These names can be one word name, two word name, or even three, four or five words name. Number of words in a name is not pre defined. I want first letter of all names to be capital letter.
For example:

  1. Ayatullah
  2. Athaul Karim
  3. Saifullah Mohammad Faisal
  4. Mohammad Tasfik Uddin Rukan

For this, I have input regex in constraint like this:
regex(., ‘^([A-Z]{1}[a-z]{1,}\s)([A-Z]{1}[a-z]{1,}\s?)+$’)

It works fine. The only problem is, it does not allow one word name. How can I fix this? Any suggestion? Thanks in advance.

@tasfik_rukan, you could do it as shown in the image shared below using the regex code regex(., '^([A-Z]{1}[a-z]{1,}\s?)+$'):

In the survey tab of your xlsform:

Image 1

Data entry screen as seen in Enketo: when a wrong entry is made

Data entry screen as seen in Enketo: when a correct entry is made

Data entry screen as seen in Enketo: when a correct entry is made

Data entry screen as seen in Enketo: when a wrong entry is made

Data entry screen as seen in Enketo: when a correct entry is made

Reference xlsform:

Regex_Constraint.xlsx (9.9 KB)

1 Like

Hi Kal_Lam, Thanks a lot for your kind reply. My problem is solved.

2 Likes