Date Field Validation: YYYY only | XM Community
Skip to main content
Solved

Date Field Validation: YYYY only


Hi everyone,
I want a textbox where the user can enter a date but only in YYYY format, and it should be from 2020 onwards.
I was unable to find a RegEx for this, and Qualtrics doesn't have only YYYY as an option.
Does anyone have any suggestions or could point me in the right direction?
I presume this can be done via in Javascript but unfortunately I don't know that. If it is the JS route, is it possible for only the "current year" and "next 2 years" i.e., 2020, 2021, and 2022, to be valid options?
Thanks!

Best answer by rondev

Create and assign the embedded data in the survey flow

View original

9 replies

MatthewM
Level 6 ●●●●●●
Forum|alt.badge.img+30
  • Level 6 ●●●●●●
  • 1069 replies
  • April 20, 2020

Hi User9184,
Can you just use Custom Validation and set rules where the entry is greater than or equal to 2020 (and less than whatever your upper limit is)?


  • Author
  • 9 replies
  • April 20, 2020

I did think of that too, but ten realized people may add years too much in the future. I've just edited my original post to say I want to have a maximum of "current year" and "next 2 years". I.e., 2020, 2021, and 2022.


rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • 1449 replies
  • April 20, 2020

Since the range is fix, you can add three embedded data (currYear, currYear1, currYear2) and value as ${date://CurrentDate/Y} , $e{ date://CurrentDate/Y + 1 } , $e{ date://CurrentDate/Y + 2 } . Now add custom validation to the text entry question as - input is equal to ${e://Field/CurrYear} OR input is equal to ${e://Field/CurrYear1} OR input is equal to ${e://Field/CurrYear2}


MatthewM
Level 6 ●●●●●●
Forum|alt.badge.img+30
  • Level 6 ●●●●●●
  • 1069 replies
  • April 20, 2020

If you're not comfortable with Javascript there are two built-in alternatives.
Here's an example using Custom Validation:
image.pngAnd here's an example using Content Validation.
image.png


  • Author
  • 9 replies
  • April 20, 2020

Thanks Matthew. This will be an ongoing form and me / whomever else will likely forget to change the dates each time. Good option for now though!


  • Author
  • 9 replies
  • April 20, 2020



  • Author
  • 9 replies
  • April 21, 2020

rondev Thanks. I will give this a go. Not done embedded data before. Do I do this at the question field, or elsewhere?


rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • 1449 replies
  • Answer
  • April 21, 2020

Create and assign the embedded data in the survey flow


  • Author
  • 9 replies
  • April 21, 2020

rondev Thanks again. I'm not sure if I put the embedded data in the wrong place, but it doesn't seem to work. No matter which year I put, I get an error.
1.PNG2.PNGIt's cut off, but I copy/pasted the exact text you provided in the custom validation field.
Could it be something to do with the spacing for currYear1 and 2? currYear doesn't have any spaces in the {} whereas the others do.


Leave a Reply