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.
Now we can call this function in the events like keypress,keydown and keyup to validate the value is number or not.
Happy Coding :-)
<script type="text/javascript">
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
<script>
Now we can call this function in the events like keypress,keydown and keyup to validate the value is number or not.
Happy Coding :-)
Yes Regular Expression also We Can do. :-)
ReplyDelete