Showing posts with label validation. Show all posts
Showing posts with label validation. Show all posts

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>

Tuesday, 19 August 2014

Input field JQuery float validation, decimal validation

$('#price').keyup(function(e){
      var entered_value = $(this).val();
  var regexPattern = /^\d{0,8}(\.\d{1,2})?$/;         
      //Allow only Number as well 0nly 2 digit after dot(.)
      if(regexPattern.test(entered_value)) {
        alert("false") ;  
      } else {
         alert("true");
      }
});

Friday, 11 April 2014

Input field enter integer only


Here's an example that limits a form field to contain only numeric input (on the fly, of course!).
<script type="text/javascript">
function numbersonly(e){
var unicode=e.charCode? e.charCode : e.keyCode
if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
if (unicode<48||unicode>57) //if not a number
return false //disable key press
}
}
</script>

<form>
<input type="text" size=18 onkeypress="return numbersonly(event)">
</form>