Hi gang! A need some help to write a script. I am trying to validate a field that allow values from a range of numbers: 20 to 500.
How can I do it?
Best answer by Nicholas
View originalHi gang! A need some help to write a script. I am trying to validate a field that allow values from a range of numbers: 20 to 500.
How can I do it?
Best answer by Nicholas
View originalHi, I think I figured out how to do this using a script that was shared on another thread.
Here’s a video showing what to do: https://www.loom.com/share/eb41687ce4804cacbdc253c9f24a58ce
Here’s the thread I referenced: Adding custom validation to form fields
And here’s the modified script I used:
<script>
lp.jQuery(function($) {
var ruleID = 'custom';
var field = 'number';
var message = 'Please enter a valid number';
var rules = module.lp.form.data.validationRules[field];
$.validator.addMethod(ruleID, function(value, field) {
var valid = ( /^([2-8][0-9]|9[0-9]|[1-4][0-9]{2}|500)$/.test(value) );
return valid || (!rules.required && !value);
}, message);
rules[ruleID] = true;
});
</script>
Good luck!
Nicholas thanks so much for your support, it is really helpful. I was trying to do this for weeks 😦, without any luck. The script is working great. The implementation is really simple with the video instructions.
Thanks again my friend!
Hi, Nicholas.
This dont fix on my page.
Why i do wrong?
http://www.kforte.com.br/teste2/ teste 1 is the field
No account yet? Create an account
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.