Reputation: 360
I wish to given my validation with min and max number and then giving a correct alert message. How to set min and max into the script below?
function isvalidated(){
//CURN
if(!$.isNumeric($('#txcurn').val())){
alert("Please enter numbers");
return false;
}
}
Upvotes: 0
Views: 8127
Reputation: 17906
how about using ternary operator :
function isvalidated(input,min,max){
if(!$.isNumeric(input)){
alert("Please enter numbers");
return false;
} else {
message = (input <= max) ? (input >= min ? "input is valid" : "input must be greater than "+min ) : "input must be smaller than "+max;
alert(message);
}
}
call it like :
isvalidated($('#txcurn').val(),1,10)
Upvotes: 1