forum

home / developersection / forums / how to prevent zero as first digit in an numeric only textfield in jquery?

How to Prevent zero as first digit in an numeric only textfield in jquery?

Anonymous User 2507 31-Oct-2014
How do I restrict if the first digit is zero (0)

$('.btn').keypress(function(e) {
      var code = e.which;
      if(($(this).val().indexOf(".") == -1 && code == 46) || (code >= 48 && code <= 57) || (code == 8) || (code >= 48 && code <= 57)){
          return true;
        }              return false;
    })
    .bind('paste',function(e) {
    e.preventDefault();
});   


Updated on 31-Oct-2014

I am a content writter !


Message
Can you answer this question?

Answer

1 Answers

Liked By