Welcome, Guest
Username: Password: Remember me

TOPIC: Special number validation

Special number validation 2 months 6 days ago #109106

  • tischer_s
  • tischer_s's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 19
  • Karma: 0
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 administrator has disabled public write access.

Special number validation 2 months 5 days ago #109137

  • tischer_s
  • tischer_s's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 19
  • Karma: 0
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
The administrator has disabled public write access.

Special number validation 2 months 5 days ago #109146

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4069
  • Thank you received: 746
  • Karma: 341
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.195 seconds
Donation Image