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

  • Home
  • SEARCH
  • 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 8630657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:06:22+00:00 2026-06-12T09:06:22+00:00

I got a regex that fails on validating my input. My regex: \d{1,5}([\.,]\d{0,2})? It

  • 0

I got a regex that fails on validating my input.

My regex: \d{1,5}([\.,]\d{0,2})?

It should validate square meters (decimal values) with a separator of either . or , and should allow up to five digits (and at least one) before the separator and up to two after it.

So it should accept:
1
1,0
1.0
12345
12345,10
12345.10

But not
.1
123456
12345,123

  • 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-06-12T09:06:23+00:00Added an answer on June 12, 2026 at 9:06 am

    In the group you’re capturing, ([\.,]\d{0,2})?, you allow the numbers to appear between 0 and 2 times, however, the entire group is marked as optional per the ending ?. Because of this, the range should be set to {1,2} instead:

    \d{1,5}([\.,]\d{1,2})?
    

    If your input is specifically a number (and not a full sentence), I would also recommend adding a leading ^ and an ending $. This will force the regex to check from the start of the string to the end (respectively). The final regex should be:

    ^\d{1,5}([\.,]\d{1,2})?$
    

    If you’re using this regex for more than validation and also want to view the matched values, you should change the current group that’s matching (the decimal portion) to a non-matching group (change ( to (?:) and then add parentheses around the full regex:

    ^(\d{1,5}(?:[\.,]\d{1,2})?)$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got this regex pattern that works with my current apache log format:
I've got the following Regex check, which makes sure that only letters, numbers and
I've got a simple JavaScript regex check (written by other developer) that works perfectly
I've got a set of regex's within a function that are working rather well
I've got the following regex that was working perfectly until a new situation arose
I've got a regex that looks for a <span> with the class name foobar
I got the following regex that almost does the work but does not exclude
So far I've got the following regex that matches against regular domains but not
Guess this is a pretty simple problem. I've got a regex and php that
i have this regex string that i got from a website to pull emails

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.