Learn free online HTML5, javascript, and jquery Tutorials by Examples

Saturday 17 May 2014

Enter only numbers inside a input field of a form using javascript

-------------------------------------------------------
<input type="text" onkeypress="return isNumberKey(event);">

<script>
    function isNumberKey(my_event)
      {
         var charCode = (my_event.which) ? my_event.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
         {
          alert("Only Numbers");
          return false;
         }
         return true;
      }
</script>


-------------------------------------------------------

No comments:

Post a Comment