- Posts: 19
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Special number validation
- tischer_s
- Topic Author
- Offline
- New Member
Less
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
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 19
- Thank you received: 0
9 years 10 months ago #109137
by tischer_s
Replied by tischer_s on topic Special number validation
Ok, I think I got it
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
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
9 years 10 months ago #109146
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Special number validation
Close, but I don't think that will allow 101-199.
Try this:
This effectively says that the string must start with 100-199 OR 10-99 OR 1-9 and may be followed by .5.
.
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.