Validation of integers, decimals, reals, and significant decimal digits the simplest javascript regular expression

Source: Internet
Author: User

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));"/&GT;&LT;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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.