Validation for text with a predefined start

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

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 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

http://www.unfpa.org

https://www.facebook.com/UNFPA https://twitter.com/unfpa
https://instagram.com/unfpa/ https://www.linkedin.com/company/unfpa
https://www.youtube.com/user/unfpa
https://plus.google.com/+unfpa/posts
http://visitor.r20.constantcontact.com/manage/optin?v=001-YNFZmXHhSP25d9kiBTi0ZxtEwaeIcM-UeLsaXPKYoHs5SAGE1WbNakIrfhkc_3wTTkXkKXbHJpBnXtbqkTATg_O174jFAyLQdNkQkPKQAk=&MERGE0=


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-users+unsubscribe@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

Hello Mark,

You can also use the substr function
https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions#CommCareFunctions-substr
:

  • 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,
  1. = ‘CD07’

Kind regards

Ismaila

··· *______________________________________________* *Ismaila DIENE*

Field Technician

Dimagi, West Africa

m: + <%28617%29%20596%206243>221 7814 78314 / +221 7601 01633
f: + <%28617%29%20596%206243>221 33 820 7375

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


On Wed, Mar 30, 2016 at 3:35 PM, Sheel Shah sshah@dimagi.com wrote:

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 onimbo@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

http://www.unfpa.org

https://www.facebook.com/UNFPA https://twitter.com/unfpa
https://instagram.com/unfpa/ https://www.linkedin.com/company/unfpa
https://www.youtube.com/user/unfpa
https://plus.google.com/+unfpa/posts
http://visitor.r20.constantcontact.com/manage/optin?v=001-YNFZmXHhSP25d9kiBTi0ZxtEwaeIcM-UeLsaXPKYoHs5SAGE1WbNakIrfhkc_3wTTkXkKXbHJpBnXtbqkTATg_O174jFAyLQdNkQkPKQAk=&MERGE0=


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-users+unsubscribe@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


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-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thanks shah, that makes more sense let me try it out.

··· On Wednesday, March 30, 2016 at 5:36:00 PM UTC+2, Sheel Shah wrote: > > 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 > > >

Thanks alot Ismail, think I still have a lot to learn

··· On Wednesday, March 30, 2016 at 5:43:16 PM UTC+2, Ismaïla Diene wrote: > > > 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/ > ______________________________________________ > > On Wed, Mar 30, 2016 at 3:35 PM, Sheel Shah <ss...@dimagi.com > wrote: > >> 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 >> >> >> -- >> 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. >> > >