Showing posts from January, 2012

Restrict the Textbox to enter only Numbers Using Javascript

Normally we get this type of requirement to accept only numbers in a text box.Suppose we have a Credit Card Number entry where we want to validate the key-press is number or not.Here i have simplified the way to enter only numbers in the text-box.Here i have written some logic to enter only numbers in textbox using javascript.
<script type="text/javascript">function isNumberKey(evt){var charCode =(evt.which)? evt.which : event.keyCode if(charCode >31&&(charCode <48|| charCode >57))returnfalse;returntrue;}<script>
Now we can call this function in theevents like keypress,keydown and keyup to validate the value is number or not.

Happy Coding :-)