0

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;   
    } 
}
4
  • have a look at jqueryvalidation.org Commented Sep 24, 2014 at 10:17
  • @Alex can be more specific ? Commented Sep 24, 2014 at 10:19
  • you can use if...else conditions Commented Sep 24, 2014 at 10:23
  • @Kenny ya...i know but how to insert min and max ? can give me some example ? Commented Sep 24, 2014 at 10:26

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

2 Comments

made an update to show how to call it with arguments
how to make it if #txtcurn equal to input then return true, if smaller or higher input than show alert

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.