Search code examples
regexformsgoogle-forms

Regular Expression Google Form only numbers in a range


I have this regex formula in a google forms field. It validates that users don't input decimals,".0" or ",00" because it messes up my calculations on submits.

enter image description here

Now i need to add to this validation a minimum number. So that users don't input a number under 120. Is this possible?

If its possible, is also posible to put a max number, so the input can only be in a certain range. Maybe 120>X<1000

Thanks!


Solution

  • You can use

    ^(1[2-9][0-9]|[2-9][0-9]{2})$
    

    This regex will only allow whole integer numbers from 120 to 999.

    See regex demo

    Explanation:

    • 1[2-9][0-9] - Alternative 1: 1 followed by 2-9 digit range, followed by 0-9 digit range
    • | - alternation operator
    • [2-9][0-9]{2} - Alternative 2: 2-9 digit range, followed by 2 occurrences of (due to {2}) 0-9 digit range.

    Here is a Google Forms demo showing this regex works