Number Validate in Text Box in PHP

18,747

I think this will work for you:

<html>
<head>
<script type="application/javascript">

  function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }

</script>
</head>

<body>
    <input type="text" name="tel_num" value="" onkeypress="return isNumberKey(event)" maxlength="10"/>
</body>
</html>
Share:
18,747

Related videos on Youtube

viru_d_great
Author by

viru_d_great

Web Developer @ mindzone IT Solutions - A'bad

Updated on September 15, 2022

Comments

  • viru_d_great
    viru_d_great about 1 year

    I need to validate the value of a text box. The text box is for the customers phone number in the format 0123456789 (ie 10 numbers only and that too live that means while entering number it won't allow user to add any alphabets or special symbols)

    The data is sent to a page (validate.php) via a forms POST method.

    I want a function that will only accept 10 numbers one after another, no letters or characters.