add a custom date validation in text entry question | XM Community
Question

add a custom date validation in text entry question

  • 26 December 2023
  • 4 replies
  • 61 views

Badge +3

Hi, I am looking for a solution to add a custom date validation in the text entry. The validations date format is mm/dd/yyyy or dd/mm/yyyy or yyyy/mm/dd. I am looking for a way to validate so entries only list MM/YYYY (without any day). Any suggestions? 


4 replies

Userlevel 6
Badge +27

Try using the below regex in custom validation matches regex option:

^(0[1-9]|1[0-2])/(19|2[0-1])\d{2}$

 

Userlevel 7
Badge +33

@Shashi has already provided you solution. I would suggest you, if you have validation for month and year only then better to use two separate dropdown for month and year. Use side by side setup and create dropdown instead. 

Badge +3

Hi, thank you for the code! I am asking a follow up question to this -- as I was able to program the custom validation. The question is requiring that the fields meet the custom validation in order to go on to the next item, though the item is a soft response. Is there a way to make the validation “work” only when there are data populated in the field? For example to allow the respondent to skip the question and leave fields blank? 

 

^(0[1-9]|1[0-2])/(19|2[0-1])\d{2}$
Userlevel 7
Badge +27

Hi, thank you for the code! I am asking a follow up question to this -- as I was able to program the custom validation. The question is requiring that the fields meet the custom validation in order to go on to the next item, though the item is a soft response. Is there a way to make the validation “work” only when there are data populated in the field? For example to allow the respondent to skip the question and leave fields blank? 

 

^(0[1-9]|1[0-2])/(19|2[0-1])\d{2}$

You can add “OR empty” as a validation condition.

Leave a Reply