Check out the LimeSurvey source code on GitHub!

Special number validation

More
2 years 8 months ago #109106 by tischer_s
Hi,

I am currently running a van Westendorp price analysis and switched from a slider to a free input field.

Now I have three requirements:

1. The scale should go up to 200
2. the steps should only allow values of 1 or +-0.5 - 1€, 1,5€ etc.
3. I only need one decimal number not 2.


I found this validation but don't know how to modify it:

/^[1-9][0-9]{0,2}(?:,?[0-9]{3}){0,3}(?:\.[0-9]{2})?$/

May anyone help me please?

Is it possible, that the follwing cases are covered?

1. 1 typed - output 1
2. 1,5 typed - output 1,5
3. 1,53 typed - error message with: "Only enter one decimal number in 0.5 steps"

Thank you very very much for your help

Best
Sebastian Tischer

Please Log in to join the conversation.

More
2 years 8 months ago #109137 by tischer_s
Ok, I think I got it :)
/^([1][0][0]|[1-9][0-9]|[0-9])((\.)[5])?$/

At least it seems to work fine now!

May anyone with more php knowledge double check it please?

Thank you all very much for your help

Best
Sebastian

Please Log in to join the conversation.

More
2 years 8 months ago #109146 by tpartner
Close, but I don't think that will allow 101-199.

Try this:
/^([1][0-9][0-9]|[1-9][0-9]|[1-9])((\.)[5])?$/

This effectively says that the string must start with 100-199 OR 10-99 OR 1-9 and may be followed by .5.


.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form