1.JS can only be a number and a decimal point 1. The text box can only enter a numeric code (the decimal point cannot be entered)<inputonkeyup= "This.value=this.value.replace (/\d/g, ')"Onafterpaste= "This.value=this.value.replace (/\d/g, ')">2. Only the number can be entered and the decimal point will be lost.<inputonkeyup= "if (IsNaN (value)) ExecCommand (' Undo ')"Onafterpaste= "if (IsNaN (value)) ExecCommand (' Undo ')"><inputname=txt1onchange= "if (/\d/.test (this.value)) {alert (' can only enter a number '); this.value=";} ">4. Only letters and kanji can be entered<inputonkeyup= "Value=value.replace (/[\d]/g, ')"Onbeforepaste= "Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text ')." Replace (/[\d]/g, ")"maxlength=10name= "Numbers">5. Only English letters and numbers can be entered, not Chinese<inputonkeyup= "Value=value.replace (/[^\w\.\/]/ig, ')">6. Only enter numbers and English<FontColor= "Red">Chun</Font><inputonKeyUp= "Value=value.replace (/[^\d|chun]/g, ')">7. Only a maximum of two digits after the decimal point (numeric, Chinese can be entered), can not enter letters and operation symbols:<inputonKeyPress= "if ((event.keycode<48 | | event.keycode>57) && event.keycode!=46 | |/\.\d\d$/.test (value)) Event.returnvalue=false ">8. Only a maximum of two digits after the decimal point (numbers, letters, Chinese can be entered), you can enter the operation symbol:<inputonkeyup= "This.value=this.value.replace (/^ (\-) * (\d+) \. ( \d\d). *$/, ' $1$2.$3 ') ">can only be numbers and decimal points and plus minus multiply onkeypress= "return event.keycode>=4&&event. keycode<=57"
2.
How JavaScript verifies whether a numberfunctionIsnumber (onum) {if(!onum)return false; varStrp=/^\d+ (\.\d+)? $/; if(!strp.test (Onum))return false; Try{ if(Parsefloat (onum)!=onum)return false; } Catch(ex) {return false; } return true; }
use JS to take float type decimal Two, example 22.127456 to 22.13 with JS take float type decimal point two, example 22.127456 take 22.13, how to do? 1. The dumbest way ... function get () {var s = 22.127456 + ""; var str = s.substring (0,s.indexof (".") + 3); alert (str);} 2. The regular effect is good<Scripttype= "Text/javascript">onload= function(){ vara= "23.456322"; varanew; varRe= /([0-9]+\.[ 0-9]{2}) [0-9]*/; Anew=A.replace (Re," $"); alert (anew);}</Script>3. He is more clever ...<Script>varNum=22.127456; alert (num math.round* -)/);</Script>4. Friends who will use new things ....<Script>varNum=22.127456; alert (num.tofixed (2));</Script>
JS Digital Verification