Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6981769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:12:00+00:00 2026-05-27T18:12:00+00:00

I need a RegEx for a numeric value with up to two decimal places

  • 0

I need a RegEx for a numeric value with up to two decimal places greater than zero and may or may not have a zero in the ones column. I should also add….whole numbers are fine. See somments below but there could be leading or trailing white spaces

Good values:
.1
0.1
1.12
123.12
92
092
092.13

Error values:
0
0.0
0.00
00
1.234
-1
-1.2
Anything less than zero
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:12:01+00:00Added an answer on May 27, 2026 at 6:12 pm

    How about this:

    ^\s*(?=.*[1-9])\d*(?:\.\d{1,2})?\s*$
    

    Explanation:

    ^            # Start of string
    \s*          # Optional whitespace
    (?=.*[1-9])  # Assert that at least one digit > 0 is present in the string
    \d*          # integer part (optional)
    (?:          # decimal part:
     \.          # dot
     \d{1,2}     # plus one or two decimal digits
    )?           # (optional)
    \s*          # Optional whitespace
    $            # End of string
    

    Test in Python:

    >>> import re
    >>> test = [".1", "0.1", "1.12", "123.12", "92", "092", "092.13", "0", "0.0", "0.00", "00", "1.234", "-1", "-1.2"]
    >>> r = re.compile(r"^\s*(?=.*[1-9])\d*(?:\.\d{1,2})?\s*$")
    >>> for item in test:
    ...     print(item, "matches" if r.match(item) else "doesn't match")
    ...
    .1 matches
    0.1 matches
    1.12 matches
    123.12 matches
    92 matches
    092 matches
    092.13 matches
    0 doesn't match
    0.0 doesn't match
    0.00 doesn't match
    00 doesn't match
    1.234 doesn't match
    -1 doesn't match
    -1.2 doesn't match
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a regex that matches the alphanumeric patterns except totally numeric ones. asdfgesod
I need a Regex that will match a java method declaration. I have come
I need strong password validation regex Special Characters - Not Allowed Spaces - Not
I need a regex to get numeric values that can be 111.111,11 111,111.11 111,111
In my app users need to be able to enter numeric values with decimal
I need to create RegEx for two different states and I am having some
I have the following regex pattern: (.NET 1.1 Regex Validator) ^(?=.*[A-Za-z])[a-zA-Z0-9@\\-_\\+\\.]{6,32}$ I need to
I need a RegEx guru to help me (I'm a noob). I have the
I have a list of alpha-numeric values that I need to search through using
Possible Duplicate: What is the ultimate postal code and zip regex? I need Regex

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.