Search code examples
regexgoogle-formsnsregularexpression

Creating a regular expression validation that limits the responses to only certain words (non case specific)?


I am writing google form validation (regular Expression). The validation is the answer must contain either Spring, Summer, Fall, Winter and the year. I also am trying to make it so it is not case sensitive. Currently, this what I have written. I have tried numerus other ways to write this and can not get it to work. Google forms allows you to select Contains, Doesn't contain, Matches, Doesn't Match

I have selected Contains and the pattern is ([A-Za-z]Spring|Fall|Summer|Winter)+[2]+[0]+[2-9]+[0-9]

So when a person enter spring, Spring, SPriNg, SPRING and a year the validation accepts it but it wont except a non season and year.


Solution

  • You could write a verbose pattern to match all case insensitive variations, and you could write the year part like 20[2-9][0-9]

    ^(?:[sS][pP][rR][iI][nN][gG]|[fF][aA][lL][lL]|[sS][uU][mM][mM][eE][rR]|[wW][iI][nN][tT][eE][rR])20[2-9][0-9]$
    

    Regex101 demo