Verify the simplest Javascript Regular Expression of integers, decimals, real numbers, and effective decimal places

Source: Internet
Author: User
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>

 

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.