How to use Number Validation for text box onkeyup by javascript?

How to use Number Validation for text box onkeyup by javascript?

i got stuck in this problem so i make some customize code of Number Validation for text box onkeyup by javascript.
it runs good and give quick alert.
you can copy and paste this code in your file and simply run the file
and you can customize the code according to your need.


<script type="text/javascript">
function checknum(s) {
return (s.toString().search(/^-?[0-9.]+$/) == 0 )
}
</script>
 <input name="phone" id="phone" type="text" class="last_bg" onkeyup="if(this.value != '' &amp;&amp; !checknum(this.value)){this.value = ''; alert('Please enter numbers only!')}"  value=""/>

Dont forget to add jquery.js file in this page

Comments