Home > DeveloperSection > Forums > How to Prevent zero as first digit in an numeric only textfield in jquery?
Maria Susan

Total Post:29

Points:107
Posted on    October-31-2014 1:23 AM

 JQuery JavaScript 
Ratings:


 1 Reply(s)
 970  View(s)
Rate this:
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();

});   



Allen Scott

Total Post:36

Points:254
Posted on    October-31-2014 1:24 AM

just try this:

if(pos == 0 && code == 48) {

    e.preventDefault();

}


Don't want to miss updates? Please click the below button!

Follow MindStick