Is there a regex or solution that tests an input field for having the following condition (as example)
I would like to test that the user input is only numbers none are decimal, greater than 0 and not greater than 20 for example. Basically I am working on client side scripting for some stuff like Quantity to add in shopping cart and I want to ensure (on client side) that he can put any values from 1 to 20, so 0 not accepted..letters, 1.3 etc...
Is there plugin or regex that tests that for me on client side?
Not sure If i got that right? Here is my attempt
var re = /^\d+$/;
var str = $(this).val();
if (re.test(str) && str > 0 && str <= 20){
status = 'success';
} else {
status = 'error';
}