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

add a custom date validation in text entry question

  • December 26, 2023
  • 6 replies
  • 706 views

Forum|alt.badge.img+3
  • Level 3 ●●●
  • 14 replies

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? 

6 replies

Shashi
Level 8 ●●●●●●●●
Forum|alt.badge.img+34
  • Level 8 ●●●●●●●●
  • 654 replies
  • December 27, 2023

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

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

 


ArunDubey
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+41
  • QPN Level 8 ●●●●●●●●
  • 589 replies
  • December 27, 2023

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


Forum|alt.badge.img+3
  • Author
  • Level 3 ●●●
  • 14 replies
  • February 6, 2024

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

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6083 replies
  • February 6, 2024

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.


Forum|alt.badge.img
  • 1 reply
  • October 24, 2024

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


Nam Nguyen
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+29
  • QPN Level 8 ●●●●●●●●
  • 1096 replies
  • October 25, 2024

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

@amadhusu ^(19[0-9]{2}|200[0-9]|201[0-9]|202[0-5])$