Regex Constraint Issues

Hi All,
I have an issue with regex… I want response of full name. I want a contraint to accept only

  1. uppercase e.g MOSES AKPAN, MOSES OKON AKPAN
  2. Apostrophe e.g GOD’SWILL EDEM UDO
  3. Hyphen e.g ENO-OBONG PAUL ARCHIBONG
  4. Full Stop e.g SAMUEL U. ADOLF

regex(.,‘[A-Z ]{1,50}’) only solved 1) above.
Thank you all.

@mosesakpan, did you have a chance to go through our support article Restricting Text Responses With Regular Expressions? It should solve your issue. If you should find anything missing, please let us know. The community should be able to help you out.

So looking at your condition, I see that you require the following in your text input:

  • All uppercase.
  • Could be comma in the text input.
  • Could be an apostrophe in the text input.
  • Could be hyphen in the text input.
  • Could be a full-stop in the text input.

@mosesakpan
To detail the requirement: Where (position) is which character allowed? E.g.

  • Only A-Z final letter of whole text? (dot also?)
  • Space (single) is only allowed between words?
  • Word (single) must start with A-Z?
  • Dot (single) must follow A-Z, and be last character of word
  • Hyphen (single) can only be between A-Z
  • Minimum of characters? (total? per word?)
  • No newlines
  • … etc.

Side-note: Pay attention to protection of personal data. Your perfect naming might need full anonymisation at the end.

You are correct Sir @Kal_Lam

Thank you @wroos. Please I didn’t understand your Side-note

@mosesakpan, this regex code should do the work for you:

regex(., ‘^[A-Z,'-.]{1,}$’)

Feel free to reach back to the community if it still does not solve your issue.

1 Like

regex(., ‘^[A-Z,’-.]{1,}$’) is not working. I modified it to regex(., ‘^[A-Z,’-.]{1,50}$’) still not working

OK. Try this and that should solve your issue:

regex(., "^[A-Z,'-.]{1,}$")

1 Like

Unfortunately it is not working

@mosesakpan,

Can you try this one?

regex(., "^[A-Z,'-.\s]{1,}$")

1 Like

@mosesakpan, I just tried this out, and it worked for me with both Enketo and Collect android app. Maybe you could use this sample XLSForm for testing:

Regex.xlsx (10.3 KB)

1 Like

@Kal_Lam I think @mosesakpan wants to include spaces aswell.

1 Like

@mosesakpan, if you wish to add space too, please follow the solution provided by @hakan_cetinkaya:

1 Like

Great! @hakan_cetinkaya got it with regex(., “^[A-Z,’-.\s]{1,}$”).
Thank you so much @Kal_Lam @hakan_cetinkaya @wroos and many others.

2 Likes