Date Field Validation: YYYY only

User9184User9184 Community Member - Trial User Qubie ✭
edited April 20 in Best Practices

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 Answers

  • rondevrondev Community Member - Trial User Wizard ✭✭✭✭✭
    Accepted Answer

    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}

  • rondevrondev Community Member - Trial User Wizard ✭✭✭✭✭
    Accepted Answer

    Create and assign the embedded data in the survey flow

Answers

  • MatthewMMatthewM Chicago, ILCommunity Member Sage ✭✭✭
    edited April 20

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

  • User9184User9184 Community Member - Trial User Qubie ✭

    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.

  • MatthewMMatthewM Chicago, ILCommunity Member Sage ✭✭✭

    If you're not comfortable with Javascript there are two built-in alternatives.

    Here's an example using Custom Validation:

    And here's an example using Content Validation.


  • User9184User9184 Community Member - Trial User Qubie ✭

    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!

  • User9184User9184 Community Member - Trial User Qubie ✭
    edited April 21
  • User9184User9184 Community Member - Trial User Qubie ✭

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

  • User9184User9184 Community Member - Trial User Qubie ✭
    edited April 21

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

    It'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.

Sign In to Comment