Custom content validation for non-numeric and character range

policyandresearchpolicyandresearch New OrleansCommunity Member Qubie ✭

Custom content validation for non-numeric and character range

Hello all!

I'm struggling to generate a multi-level content validation code to restrict responses on a participant ID question. Participants will generate their ID's by entering the first two letters of their first name and the first two letters of their last name into two separate text entry questions. I want to restrict their response options to non-numeric responses of strictly 2 characters (John = JO). There is custom validation that only applies to numeric range, there is content validation that can restrict responses to non-numeric entries, and there is character range validation that restricts the number of characters entered but does not distinguish between numeric and non-numeric responses.

Qualtrics told me a custom code could solve this problem, restricting both the content range and the characters to non-numeric, can anyone help?

Bonus points if the solution includes a custom error message when these values are entered incorrectly.

Thanks!

Tagged:

Answers

  • ShashiShashi IndiaCommunity Member Wizard ✭✭✭✭✭

    Hello @policyandresearch ,

    You can use match regex option in custom validation and use below regex:

    ^[A-Z]{2}$

  • policyandresearchpolicyandresearch New OrleansCommunity Member Qubie ✭

    Thank you so much for your quick reply!

    I'm having another problem. For the same ID question we ask participants to input their two digit birth month. I want to limit response options to 01-12 (02, 03, 04...). To do this I amended the code you provided to ^[01-12]{2}$ This seemed to work at first, but now I realize that for some reason it validates responses 00 (which I don't want), 01, 02, 10, 11, and 12. It will not validate responses 03-09. Any idea why this is happening? Or how to amend the code to restrict 00 but allow 01-12?

    Thank you!

  • ShashiShashi IndiaCommunity Member Wizard ✭✭✭✭✭

    @policyandresearch said:
    Thank you so much for your quick reply!

    I'm having another problem. For the same ID question we ask participants to input their two digit birth month. I want to limit response options to 01-12 (02, 03, 04...). To do this I amended the code you provided to ^[01-12]{2}$ This seemed to work at first, but now I realize that for some reason it validates responses 00 (which I don't want), 01, 02, 10, 11, and 12. It will not validate responses 03-09. Any idea why this is happening? Or how to amend the code to restrict 00 but allow 01-12?

    Thank you!

    Try using the below regex.......

    ^0[1-9]|1[0-2]$

  • policyandresearchpolicyandresearch New OrleansCommunity Member Qubie ✭

    Thank you for trying to solve this problem for me! That code does restrict 00 and allows 01-09, but it doesn't restrict responses to only 2 characters, allowing responses like 011, 021 etc etc to get through. Any suggestion on how to fix this? Thank you!

  • ShashiShashi IndiaCommunity Member Wizard ✭✭✭✭✭

    @policyandresearch said:
    Thank you for trying to solve this problem for me! That code does restrict 00 and allows 01-09, but it doesn't restrict responses to only 2 characters, allowing responses like 011, 021 etc etc to get through. Any suggestion on how to fix this? Thank you!

    Try the below regex:

    ^0[1-9]|1[0-2]{2}$

  • policyandresearchpolicyandresearch New OrleansCommunity Member Qubie ✭

    thank you again for your consistent replies. Unfortunately, responses like 022, 034 etc are still getting through. Any idea on how to restrict characters to 2 exactly? Thank you!

  • ShashiShashi IndiaCommunity Member Wizard ✭✭✭✭✭

    @policyandresearch said:
    thank you again for your consistent replies. Unfortunately, responses like 022, 034 etc are still getting through. Any idea on how to restrict characters to 2 exactly? Thank you!

    With this ^0[1-9]|1[0-2]$ regex add one more regex validation with AND condition as ^[0-9]{2}$

Sign In to Comment