Users Pricing

forum

Home Forums How to Prevent zero as first digit in an numeric only textfield in jquery? – MindStick

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

Anonymous User 2666 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();
});   


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md