Document directory
- After entering the information, press enter to verify it! (The simplest !)
After entering the information, press enter to verify it! (The simplest !)
Positive Integer:
Negative integer:
Integer:
Decimal point:
Negative decimal:
Small Number:
Number of instances:
Retain 1 decimal point:
Retain 2 decimal places:
Retain three decimal places:
Note: ie6.0, ie7.0, ie8.0, and Firefox/3.0.11 are successfully tested.
Original Author! Reprint please explain the source: http://blog.csdn.net/xxd851116
[Test source code ]:
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <title> complete the simplest Regular Expression for verifying numbers </title> <br/> </pead> <br/> <body> <br/> <p> after entering the information, press enter to verify it! (The simplest !) </H3> <br/> positive integer: <input type = "text" size = "20" onkeydown = "If (event. keycode = 13) Alert (/^/d + $ /. test (this. value); "/> <br/> negative integer: <input type =" text "size =" 20 "onkeydown =" If (event. keycode = 13) Alert (/^-/d + $ /. test (this. value); "/> <br/> INTEGER: <input type = "text" size = "20" onkeydown = "If (event. keycode = 13) Alert (/^ -? /D + $ /. test (this. value); "/> <br/> decimal point: <input type = "text" size = "20" onkeydown = "If (event. keycode = 13) Alert (/^/d + /. /d + $ /. test (this. value); "/> <br/> negative decimal point: <input type = "text" size = "20" onkeydown = "If (event. keycode = 13) Alert (/^-/d + /. /d + $ /. test (this. value); "/> <br/> small number: <input type = "text" size = "20" onkeydown = "If (event. keycode = 13) Alert (/^ -? /D + /. /d + $ /. test (this. value); "/> <br/> Number of instances: <input type = "text" size = "20" onkeydown = "If (event. keycode = 13) Alert (/^ -? /D + (/./d + )? $ /. Test (this. value); "/> <br/> retain 1 decimal point: <input type = "text" size = "20" onkeydown = "If (event. keycode = 13) Alert (/^ -? /D + (/./d {1, 1 })? $ /. Test (this. value); "/> <br/> retain two decimal places: <input type = "text" size = "20" onkeydown = "If (event. keycode = 13) Alert (/^ -? /D + (/./d {1, 2 })? $ /. Test (this. value); "/> <br/> retain three decimal places: <input type = "text" size = "20" onkeydown = "If (event. keycode = 13) Alert (/^ -? /D + (/./d {1, 3 })? $/. Test (this. Value); "/> <br/> </body> <br/> </ptml>