Showing posts with label enter integer only jquery. Show all posts
Showing posts with label enter integer only jquery. Show all posts

Saturday 16 December 2017

Jquery allow decimal & integer script



$(document).ready(function(){
  $(".notallowdec").keypress(function (e){
      if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57) ) {
            return false;
        }else{
    
    }
    });
  $('.allowdec').keypress(function(event){
    if ((event.which != 46 || $(this).val().indexOf('.') != -1)&&
(event.which < 48 || event.which > 57))
    {
    if((event.which != 46 || $(this).val().indexOf('.') != -1))
    {
      //alert('Multiple Decimals are not allowed');
    }
    event.preventDefault();
    }
    if(this.value.indexOf(".")>-1 && (this.value.split('.')[1].length > 1))
    {
    //alert('Two numbers only allowed after decimal point');
    //event.preventDefault();
    }
  });
  
});

Tuesday 23 September 2014

Input field enter integer only in jQuery

$(document).ready(function () {
    //called when key is pressed in textbox
    $("#quantity").keypress(function (e) {
        //if the letter is not digit then display error and don't type anything
        if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
            //display error message
            $("#errmsg").html("Digits Only").show().fadeOut("slow");
            return false;
        }
    });
});

Number :
<input type="text" name="quantity" id="quantity" /> <span id="errmsg"></span>