Validation for text with a predefined start

11 views
Skip to first unread message

Mark Onimbo

unread,
Mar 29, 2016, 11:01:49 AM3/29/16
to commcare-users
How do i write validation for a text question that only accepts text values that start with CD07 eg CD07 01, or CD07 4, anything that does not start with CD07 should be rejected

Sheel Shah

unread,
Mar 30, 2016, 11:36:00 AM3/30/16
to commcar...@googlegroups.com
Hey Mark,

You could use add a regular expression validation to the text question so that it only accepts values that start with CD07.  

Otherwise, what I normally do is:
- Add a question list (this will make questions inside this appear on the same screen)
- Inside the question list add a label with the text that you want them to always enter (i.e. "CD07")
- Underneath it, add a text question that lets them enter the second part of the value (i.e. 04 or 7) 
- Add a hidden value (i.e. cd7_code that has a calculation that combines "CD07" and the value they entered.  So concat ('CD07', /data/questionlist/cd7_suffix). 

Thanks,
Sheel

On Tue, Mar 29, 2016 at 11:01 AM, Mark Onimbo <oni...@unfpa.org> wrote:
How do i write validation for a text question that only accepts text values that start with CD07 eg CD07 01, or CD07 4, anything that does not start with CD07 should be rejected



           

--
You received this message because you are subscribed to the Google Groups "commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commcare-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Sheel Shah
Project Manager | Dimagi
m: +1.781.428.5419 | skype: sheel_shah


Ismaïla Diene

unread,
Mar 30, 2016, 11:43:16 AM3/30/16
to commcar...@googlegroups.com

Hello Mark,

You can also use the substr function:
  • substr(., 0, 4) should get you the 4 first characters of your text question.
  • So in the validation condition of you text question put: substr(., 0, 4) = 'CD07'
Kind regards

Ismaila
______________________________________________
Ismaila DIENE

Field Technician

Dimagi, West Africa

m: +221 7814 78314 / +221 7601 01633
f: +221 33 820 7375

skype: isaack007
web: http://www.dimagi.com/
______________________________________________

Mark Onimbo

unread,
Mar 31, 2016, 6:49:27 AM3/31/16
to commcare-users
Thanks alot Ismail, think I still have a lot to learn

Mark Onimbo

unread,
Mar 31, 2016, 6:50:29 AM3/31/16
to commcare-users
Thanks shah, that makes more sense let me try it out. 
Reply all
Reply to author
Forward
0 new messages