JavaScript to restrict respondents input to a few ranges

0

Hello Gizmo Community,

 

I am building a simple survey but I am facing a technical question :

The only way we control the respondent identity is through a unique ID that was given to them prior to the survey.

They input this number in a text box and I would like to validate if their answer is at least in the possible range.

If it’s not, then the survey should return an error message.

It has range [0000] to [0999] then [3000] to [3999] then [4000] to [4999] then  finally [6000] to [6999].

I would use regex but I don’t know if then engine accept conditional formulas.

I also took a look at Java (never used it before) and maybe that what I need:

 

 

Can someone help here?

 

Many thanks,

 

QME

IS answered
    1
    IS 2.20K Rep.

    RegEx is really the best way to go here.

    I think a pattern that works for you would be:

    ^(0|3|4|6)\d{3}$

     

    An explanation of the pattern is:

    ^  = the string starts here, no preceding characters allowed

    (0|3|4|6)  = a character that is either 0, 3, 4, or 6

    \d  = a numeric digit

    {3} = need exactly three of the preceding (in this case, need exactly 3 numeric digits)

    $ = the string ends here, no following characters allowed.

     

    IS answered
      ×

      Login

      Question stats

      • Active
      • Views1078 times
      • Answers1 answer
      • Followers1 follower