Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Special number validation

  • tischer_s
  • tischer_s's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 10 months ago #109106 by tischer_s
Special number validation was created 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
The topic has been locked.
  • tischer_s
  • tischer_s's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 10 months ago #109137 by tischer_s
Replied by tischer_s on topic Special number validation
Ok, I think I got it :)
Code:
/^([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
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 10 months ago #109146 by tpartner
Replied by tpartner on topic Special number validation
Close, but I don't think that will allow 101-199.

Try this:
Code:
/^([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.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose