Click here to Skip to main content
15,910,886 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i give validation for text box. it should have only numbers using java script
Posted

Try this:
HTML
<HTML>
   <HEAD>
   <SCRIPT language=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 id="txtChar" onkeypress="return isNumberKey(event)" type="text" name="txtChar">
   </BODY>
</HTML>


Refer:
Allow Only Numbers in a Textbox[^]
Similar discussion: Restricting input to textbox: allowing only numbers and decimal point[^]
 
Share this answer
 
look this tips in which i use javascript function for only take numeric values. this function also accept only one '.' and + or - sign. How to Add and Use Javascript Files's Functions in DLL[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900