Date Field Validation: YYYY only | XM Community
Solved

Date Field Validation: YYYY only

  • 20 April 2020
  • 9 replies
  • 271 views

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!

icon

Best answer by rondev 21 April 2020, 03:44

View original

9 replies

Userlevel 7
Badge +30

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)?

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.

Userlevel 7
Badge +22

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}

Userlevel 7
Badge +30

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

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!


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

Userlevel 7
Badge +22

Create and assign the embedded data in the survey flow

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