add a custom date validation in text entry question | XM Community
Skip to main content

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? 

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

^(001-9]|110-2])/(19|220-1])\d{2}$

 


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


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? 

 

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

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? 

 

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

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


What regex can I use if I want to restrict the years entered to 1900 - 2025?


What regex can I use if I want to restrict the years entered to 1900 - 2025?

@amadhusu ^(1990-9]{2}|20000-9]|20110-9]|20220-5])$


Leave a Reply