Need Regular Expression to validate for 2 decimal places

Posted on 2008-11-11
Last Modified: 2012-05-05
Would like the regular expression to force a user to supply a decimal with 2 decimal places. Example : 12.56
Question by:jazzcatone
    LVL 59

    Accepted Solution

    Think like this:


    Author Closing Comment

    Looks like this worked. Thanks .
    LVL 59

    Expert Comment

    by:Kevin Cross
    Glad. Figured as this should be consistent across most environments, but tested in Java.

    +Must begin with number.
    +Must have . in it.
    +Must end with exactly two digits.
    LVL 59

    Expert Comment

    by:Kevin Cross
    If you want to allow .25 the same as 0.25, then you can change to this:


    Not sure if this works in all environments, but it should but you also have the \d representing numeric values.


    Hope all that helps.

    Expert Comment

    i need to validate a number like 1.20

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
    As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now