Regular expressions that retain two decimal places

Source: Internet
Author: User

A percent regular expression that retains up to two decimal places: /^\d+\.? \d{0,2}%$/

44.5% 44.66% 0.3% 5% All right 33.444%-5.66% are wrong

A percent regular expression that has and retains only two decimal places: /^\d+\.? \d{2}%$/

44.66% correct 0.3% 5% 33.444% -5.66% all wrong

Js:/^\d+\.? \d{0,2}%$/
Java: ^\\d+\\.? \\d{0,2}%$

function Ispercent () {
var str = "0.47%";
alert (str);
if (str.length!=0) {
Alert (1);
var reg = /^\d+\.? \d{2}%$/;
var r = Str.match (reg);
Alert (R);
if (r==null)
Alert (' Sorry, you have entered an incorrect percentage format! '); Please change "date" to the name of the property you need to verify!
}
}

Regular expressions that retain two decimal places

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.