Skip to main content

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?


Hi, 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.validationRulesnfield];

$.validator.addMethod(ruleID, function(value, field) {

var valid = ( /^( 2-8](0-9]|900-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!


That’s great to hear!


Hi, Nicholas.


This dont fix on my page.


Why i do wrong?


http://www.kforte.com.br/teste2/ teste 1 is the field


Reply