Once you have entered, press ENTER to verify! (self-thought is the simplest!) )
Positive integers:
Negative integers:
Integer
Positive decimals:
Negative decimals:
Decimal
Real
Keep 1 decimal places:
Keep 2 decimal places:
Keep 3 decimal places:
Description: IE6.0, IE7.0, IE8.0, firefox/3.0.11 under test
Author Original! Reprint please indicate source: http://blog.csdn.net/xxd851116
<! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">"http://www.w3.org/1999/xhtml">positive integers:<input type="text"Size=" -"onkeydown="if (Event.keycode = =) Alert (/^\d+$/.test (This.value));"/><br/>negative integers:<input type="text"Size=" -"onkeydown="if (Event.keycode = =) Alert (/^-\d+$/.test (This.value));"/><br/>integer:<input type="text"Size=" -"onkeydown="if (Event.keycode = =) Alert (/^-?\d+$/.test (This.value));"/><br/>Positive decimals:<input type="text"Size=" -"onkeydown="if (Event.keycode = =) Alert (/^\d+\.\d+$/.test (This.value));"/><br/>Negative Decimals:<input type="text"Size=" -"onkeydown="if (Event.keycode = =) Alert (/^-\d+\.\d+$/.test (This.value));"/><br/>decimal:<input type="text"Size=" -"onkeydown="if (Event.keycode = =) Alert (/^-?\d+\.\d+$/.test (This.value));"/><br/>Real numbers:<input type="text"Size=" -"onkeydown="if (Event.keycode = =) Alert (/^-?\d+ (\.\d+) $/.test (This.value));"/><br/>Keep 1 decimal places:<input type="text"Size=" -"onkeydown="if (Event.keycode = =) Alert (/^-?\d+ (\.\d{1,1})? $/.test (This.value));"/><br/>Keep 2 decimal places:<input type="text"Size=" -"onkeydown="if (Event.keycode = =) Alert (/^-?\d+ (\.\d{1,2})? $/.test (This.value));"/><br/>Keep 3 decimal places:<input type="text"Size=" -"onkeydown="if (Event.keycode = =) Alert (/^-?\d+ (\.\d{1,3})? $/.test (This.value));"/><BR/></body>Attached: Bug resolution, mainly for 023, the front plus 0 of the situation
/^(?! 0 [1-9]) -?\d+ (\.\d{1,3})? $/
Validation of integers, decimals, reals, and significant decimal digits the simplest javascript regular expression