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 8806349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:06:24+00:00 2026-06-14T02:06:24+00:00

So, I have this if statement: if (String(val).search(/^((\d+(((\,\d{3,})+)?)(\.\d+)?)|(\.\d+))$/) !== -1) Which says (as far

  • 0

So, I have this if statement:
if (String(val).search(/^((\d+(((\,\d{3,})+)?)(\.\d+)?)|(\.\d+))$/) !== -1)

Which says (as far as I am aware):
The string must either start with at least one digit, or a ..
If the string starts with a digit there can optionally be commas in the string, as long as the commas are followed by at least three digits.
If the string has a . in it, it must be followed by at least one digit.
There can be only one .

So, strings like:

5
5.00
5000
5,000
5000.00
5,000.00

Will all return true

But strings that contain anything but 0-9 , . or are malformed will return false.
so strings like this:

5,00
5,00.00
5.00.00
a5

Now, the above works, but I am wondering if there is any way to simplify it?

  • 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-14T02:06:25+00:00Added an answer on June 14, 2026 at 2:06 am

    You can remove some redundant parenthesis:

    ^(\d+((\,\d{3,})+)?(\.\d+)?|\.\d+)$
    

    And something like (( ... )+)? can be replaced by: ( ... )*, so the final regex might look like this:

    ^(\d+(\,\d{3,})*(\.\d+)?|\.\d+)$
    

    And if you’d like to reject input like:

    50000,000,000.0
    

    and only allow for:

    5,000,000.0
    50,000,000.0
    500,000,000.0
    

    Then do something like this:

    ^(\d{1,3}(\,\d{3})*(\.\d+)?|\.\d+)$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have this statement in my SQL View (SQL Server 2008 R2) which
i have this MySQL statement from a search page, the user enters there postcode
I have this statement: String cap = Regex.Replace(winCaption, @[^\w\.@-], ); that transforms Hello |
Let say i have a string like this 'this is a statement' and if
I have this if statement, which returns the result as a AsQueryable to an
I have this Linq statement: List<string> phoneNumbers = from t in fixedLineData select t.phoneNumber.Distinct();
I am new to this, I have this: public Builder id (String val) {
I have this statement in my c program and I want to optimize. By
We have this statement: (SELECT res_bev.bev_id, property_value.name AS priority FROM res_bev, bev_property, property_value WHERE
I have this SQL statement: SELECT * FROM history WHERE (fk_person = 2119) AND

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.