Javascript judgment number
Bind events to the text box. When the focus enters the text box, cancel document. onkeydown and assign a value to document. onkeydown again when the focus leaves. For example, the text box can be written as follows: <input type = "text" onfocus = "document. onkeydown = jumppage" onblur = "document. onkeydown = NULL;"/>
// Integer format <br/> patternsdict. long =/^ (0 | [1-9]/D *) $/; <br/> // decimal format <br/> patternsdict. double =/^ (0 | [1-9]/D *)/. (/d +) $/; <br/> // value format <br/> patternsdict. number =/^ (0 | [1-9]/D *) $ | ^ (0 | [1-9]/D *)/. (/d +) $/; <br/> // natural number <br/> patternsdict. positive =/^ ([1-9]/D *) $/; <br/> // negative integer <br/> patternsdict. negative =/^ (-([1-9]/D *) $/; <br/> 1. only numeric code can be entered in the text box (decimal point cannot be entered) <br/> <input onkeyup = "this. value = This. value. replace (// D/g, '')" onafterpaste = "This. value = This. value. replace (// D/g, '')"> <br/> 2. only numbers are allowed, and decimal points are allowed. <br/> <input onkeyup = "If (isnan (value) Execcommand ('undo ')" onafterpaste = "If (isnan (value) Execcommand ('undo ') "> <br/> <input name = txt1 onchange =" If (// D /. test (this. value) {alert ('only numbers allowed '); this. value = '';}"> <br/> 3. method 2: Number and decimal point <br/> <input type = text t_value = "" o_value = "" onkeypress = "If (! This. value. Match (/^ [/+/-]? /D *? /.? /D *? $/) This. value = This. t_value; else this. t_value = This. value; If (this. value. Match (/^ (?: [/+/-]? /D + (?: //./D + )?)? $/) This. o_value = This. Value "onkeyup =" If (! This. value. Match (/^ [/+/-]? /D *? /.? /D *? $/) This. value = This. t_value; else this. t_value = This. value; If (this. value. Match (/^ (?: [/+/-]? /D + (?: //./D + )?)? $/) This. o_value = This. Value "onblur =" If (! This. value. Match (/^ (?: [/+/-]? /D + (?: //./D + )? |/./D *?)? $/) This. value = This. o_value; else {If (this. value. match (/^ /. /d + $/) This. value = 0 + this. value; If (this. value. match (/^ /. $/) This. value = 0; this. o_value = This. value} "> <br/> 4. only letters and Chinese characters can be entered. <br/> <input onkeyup = "value = value. replace (/[/d]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[/d]/g, '')" maxlength = 10 name = "Numbers"> <br/> 5. only English letters and numbers are allowed. Chinese characters are not allowed. <br/> <input onkeyup = "Va Lue = value. replace (/[^/W /. //]/ig, '')"> <br/> 6. only numbers and English letters can be entered <font color = "red"> Chun </font> <br/> <input onkeyup = "value = value. replace (/[^/d | Chun]/g, '')"> <br/> 7. only two digits can be entered after the decimal point. Letters and operator numbers are not allowed: <br/> <input onkeypress = "If (event. keycode <48 | event. keycode> 57) & event. keycode! = 46 | //. /D/d $ /. test (value) event. returnvalue = false "> <br/> 8. only two digits (numbers, letters, and Chinese characters) can be entered after the decimal point. You can enter the operator number: <br/> <input onkeyup = "this. value = This. value. replace (/^ (/-) * (/d + )/. (/D/d ). * $/, '$1 $2. $ 3') ">