How to only allow users to input number in JavaScript

When you are surfing on the internet ,you must encounter this kind of situation: a text form only allow you to input number,other characters do not be allowed, and how to realize this kind of function, we will use javascript to realize it. look at source code below:

1.html page source code for example:

 <input type="text" style="ime-mode:disabled" onkeyup="return ValidateNumber(this,value)" />

2.we realize function:ValidateNumber by JavaScript:

Only allow integer, not point number

 function ValidateNumber(e, pnumber){

if (!/^\d+$/.test(pnumber)){

e.value = /^\d+/.exec(e.value);}

return false;

}

If you want to allow users to input point number,you can change this function like this:

 function ValidateNumber(e, pnumber)
 {
 if (!/^\d+[.]?\d*$/.test(pnumber))
 {
 e.value = /^\d+[.]?\d*/.exec(e.value);
 }
 return false;
 }

,