Restrict input types: Numbers, decimal points, and negative numbers, and input negative numbers
The input type is limited. Requirements: numbers can contain decimal points and negative numbers, and the negative number can only appear at the leftmost. the decimal point and negative number can only appear once, and cannot exceed 2 digits after the decimal point.
This setting is most suitable for the input of the currency amount. It has the n-digit limit (n> 1) after the decimal point and the n-digit limit (n> 1); it has positive and negative values (borrow); the negative number can only appear at the leftmost; the decimal point and negative number can only appear once.
In the <Head> ...... </Head>
<SCRIPT language = "javascript"> function checkNum (obj) {// check whether it is a non-numeric value if (isNaN (obj. value) {obj. value = "";} if (obj! = Null) {// check whether two if (obj. value. toString (). split (". "). length> 1 & obj. value. toString (). split (". ") [1]. length> 2) {alert ("no more than two digits after the decimal point! "); Obj. value =" ";}}</SCRIPT>
In the INPUT box
<Input type = "text" name = "cash" id = "cash" onkeyup = "checkNum (this)"/>