0

This is my jQuery code

$(document).ready(function () {

  $('#txtLoadCode').keydown(function (key) {

    if ($(this).val().substring(0, 1) == '0') {
      $(this).val('');
      return false;
    } else {
      var keycode = (key.which) ? key.which : key.keyCode;
      var code = document.getElementById('<%=txtLoadCode.ClientID%>').value;
      if ((!(keycode == 8 || keycode == 46)) && (keycode < 48 || keycode > 57)) {
        return false;
      } else {
        //Condition to check textbox contains ten numbers or not 
        if (code.length < 5 || keycode == 8) {
          return true;
        } else {
          return false;
        }
      }
    }
  });
});

This helps me to accept a 5 digit number. But when I enter only 0, it still accepts that. I want to avoid that.

Please help

2
  • try on keyup event..... Commented Feb 7, 2014 at 10:37
  • glad it helped..posted as an answer...upvote and mark as answer :) Commented Feb 7, 2014 at 11:23

1 Answer 1

1

Instead of using keydown event ...try on keyup event

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

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.