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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:36:38+00:00 2026-05-22T20:36:38+00:00

Possible Duplicate: What's a C# regular expression that'll validate currency, float or integer? How

  • 0

Possible Duplicate:
What's a C# regular expression that'll validate currency, float or integer?

How can I validate currency amount using regular expressions in JavaScript?

Decimals separator: ,

Tens, hundreds, etc. separator: .

Pattern: ###.###.###,##

Examples of valid amounts:

1
1234
123456

1.234
123.456
1.234.567

1,23
12345,67
1234567,89

1.234,56
123.456,78
1.234.567,89

EDIT

I forgot to mention that the following pattern is also valid: ###,###,###.##

  • 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-22T20:36:38+00:00Added an answer on May 22, 2026 at 8:36 pm

    Based solely on the criteria you gave, this is what I came up with.

    /(?:^\d{1,3}(?:\.?\d{3})*(?:,\d{2})?$)|(?:^\d{1,3}(?:,?\d{3})*(?:\.\d{2})?$)/

    Demo

    It is ugly, and it will only get worse as you find more cases that need to be matched. You’d be well served to find and use some validation library rather than try to do this all yourself, especially not in a single regular expression.

    Updated to reflect added requirements.


    Updated again in regard to comment below.

    It would match 123.123,123 (three trailing digits instead of two) because it would accept either comma or period as both the thousands and decimal separators. To fix that, I’ve now essentially doubled up the expression; either it matches the whole thing with commas for separators and a period as the radix point, or it matches the whole thing with periods for separators and a comma as the radix point.

    See what I mean about it getting messier? (^_^)


    Here’s the verbose explanation:

    (?:^           # beginning of string
      \d{1,3}      # one, two, or three digits
      (?:
        \.?        # optional separating period
        \d{3}      # followed by exactly three digits
      )*           # repeat this subpattern (.###) any number of times (including none at all)
      (?:,\d{2})?  # optionally followed by a decimal comma and exactly two digits
    $)             # End of string.
    |              # ...or...
    (?:^           # beginning of string
      \d{1,3}      # one, two, or three digits
      (?:
        ,?         # optional separating comma
        \d{3}      # followed by exactly three digits
      )*           # repeat this subpattern (,###) any number of times (including none at all)
      (?:\.\d{2})? # optionally followed by a decimal perioda and exactly two digits
    $)             # End of string.
    

    One thing that makes it look more complicated is all the ?: in there. Normally a regular expression captures (returns matches for) all of the subpatterns too. All ?: does is say to not bother to capture the subpattern. So technically, the full thing would still match your entire string if you took all of the ?: out, which looks a bit clearer:

    /(^\d{1,3}(\.?\d{3})*(,\d{2})?$)|(^\d{1,3}(,?\d{3})*(\.\d{2})?$)/

    Also, regular-expressions.info is a great resource.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Regular expression that matches valid IPv6 addresses Can any one know the
Possible Duplicate: Using regular expression within a stored procedure I need to validate a
Possible Duplicate: Regular expression to match hostname or IP Address? I need to validate
Possible Duplicate: Useful Regular Expression Tutorial Hello, I recently started coding in javascript. I
Possible Duplicate: What regular expression can never match? how do i write a regular
Possible Duplicate: What is the best regular expression for validating email addresses? I'm using
Possible Duplicate: Getting DIV content with Regular Expression Let me first tell you that
Possible Duplicates: How to remove Bullets from the text using javascript regular expression How
Possible Duplicates: Checking for a valid url using Javascript Regular Expressions PHP validation/regex for
Possible Duplicate: How do you pass a variable to a Regular Expression JavaScript? how

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.