3

Problem with isNumeric validation with my form. $.isNumeric($('input#director').val()) does not work. I want to check if the input value is only a string, and if the user entered numbers by mistake, the label error will appear. but problem is, it is not working.

$(function() {
   $('.error').hide();
   $(".submit").click(function() {
      $('.error').hide();
      var director = $("input#director").val();
      if(director=="" || ($.isNumeric($('input#director').val()))){
     $("label#director_error").show();
     $("input#director").focus();
     return false;
  }
   }
}
1
  • 1
    Why do you repeat $('input#director').val() when you already put it in the variable director? Commented Jun 27, 2013 at 6:00

3 Answers 3

4
 if(director=="" && isNumeric(director).val())){ // and so on

Try this

Sign up to request clarification or add additional context in comments.

Comments

2

try this way:

$("#btnsubmit").click(function() 
{ 
    if($('input#director').val()==="" || $.isNumeric($('input#director').val()))
    {
      alert("error");
        //your other code 
    }
});

fiddle: http://jsfiddle.net/shree/cV4Pt/

Comments

-1
$(function() {
   $('.error').hide();
   $(".submit").click(function() {
      $('.error').hide();
      var director = $("input#director").val();
      if(director=="" || isNumeric($('input#director').val())){
     $("label#director_error").show();
     $("input#director").focus();
     return false;
  }
   }
}

please use normal isNumeric function

Comments

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.