Regular expression for ensuring the validity of a currency amount with a specific minimum value

Currently, I have a regular expression that successfully validates money.

^\d{1,3}(,\d{3})*$

However, I now need to modify it to include a minimum amount requirement of 20,000. Can someone assist me with this adjustment?

Fiddle:

fiddle updated with correct expression

Answer №1

After going through the comments, it appears that using regex may not be the most suitable approach for your task, but you are determined to make it work. Your requirement seems to involve validating a comma-separated string starting at 20,000, where each subsequent part of the number consists of 3 digits. Here is a possible regex solution:

^(?:[2-9]\d|[1-9]\d\d|[1-9],\d{3})(?:,\d{3})+$

You can test this regex pattern in an online demo.


  • ^ - Marks the start of the string.
  • (?: - Opens the first non-capture group.
    • [2-9]\d - Matches a digit between 2 and 9 followed by any digit.
    • | - Or.
    • [1-9]\d\d - Matches a digit between 1 and 9 followed by two digits.
    • | - Or.
    • [1-9],\d{3} - Matches a digit between 1 and 9 followed by a comma and three digits.
    • ) - Closes the first non-capture group.
  • (?: - Opens the second non-capture group.
    • ,\d{3} - Matches a comma followed by three digits.
    • )+ - Closes the second non-capture group and allows repetition at least once.
  • $ - Marks the end of the string.

Alternatively, you could use lookaheads, like so:

^(?=.{6,})(?!1.{5}$)[1-9]\d?\d?(?:,\d{3})+$

Test this alternative pattern in the online demo.


  • ^ - Marks the start of the string.
  • (?=.{6,} - Positive lookahead for at least 6 characters.
  • (?!1.{5}$) - Negative lookahead for a sequence of 1 followed by 5 characters until the end of the string.
  • [1-9]\d?\d? - Matches a digit between 1 and 9 followed by up to two optional digits (can also be written as [1-9]\d{0,2}).
  • (?: - Opens the second non-capture group.
    • ,\d{3} - Matches a comma followed by three digits.
    • )+ - Closes the non-capture group with repeating at least once.
  • $ - Marks the end of the string.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having issues installing Parcel through npm - Encountered an error while parsing package.json information

After creating a package.json file using the command npm init in my project folder, I proceeded to run npm i parcel --save-dev which resulted in an error message: C:\Users\XPRESS\Desktop\starter>npm i parcel --save-dev npm ERR! code ...

The checkbox will be automatically checked whenever there is any modification in the textbox

I'm currently working on a Grid view with a checkbox and two textboxes. What I want is for the checkbox to be automatically checked whenever there is a change in one of the textbox values, for example switching from 0 to 1. This project is being devel ...

Node.js and Angular.js communication: from requests to responses

Efforts are being made to solicit data from a node.js server through angular.js. However, an unexpected challenge persists: post-data response, a stark white browser screen shows up with the JSON object in plain sight. The goal is for angular.js to acknowl ...

Adding a question mark at the top of the content in a txt file using node.js's

When I use the fs.readFile() function to retrieve data from a .txt file, I notice that the content begins with "?Alex libman". Here is the code snippet: fs.readFile(__dirname+"/txts/generate/titles0.txt", "utf-8", function (ex, titles) { var titlesArr = ...

Discover a personalized message and alter its hue using JavaScript and CSS styling

I've hit a roadblock while creating my website with WordPress and a custom theme. Although I can easily inject custom Js or CSS, I need advice on how to achieve the following: How can I locate the symbol ★ within the content and change its color? ...

Steps to automatically launch a URL upon button click and executing PHP script

I have a Joomla website and I am facing a challenge in automatically triggering a modal window that displays a web page based on parameters passed through the URL. The scenario on my website is as follows: A trip leader selects a trip and schedules it by ...

Guide on parsing and totaling a string of numbers separated by commas

I am facing an issue with reading data from a JSON file. Here is the code snippet from my controller: myApp.controller("abcdctrl", ['$scope', 'orderByFilter', '$http', function ($scope, orderBy, $http) { console.log('abc ...

- The click function is failing to work after an ajax call [Potential event delegation problem]

I have a webpage where I update the contents of an unordered list using $.get() every 5 seconds. The issue I am facing is that the click function for the list items is not working properly. Even though the list items are being updated correctly, there se ...

Tips for displaying a loading spinner each time the material table is loading

Hey there, I'm currently working on an Angular project where I need to display a table using Material Table. To indicate that the table is loading, I've defined a variable called isLoading. Here's how it works: In my TypeScript file: @Com ...

Line of cubes - tap on a single cube and the others gracefully slide away from view

I am working on a project where I need to create a row of blocks. The goal is for the blocks to slide off the screen when one is clicked, leaving the clicked block in the first position. For instance: https://i.sstatic.net/IB5LI.jpg I attempted using jQ ...

Activating Jquery toggle on several elements instead of just the specified element

Hey everyone, I have a question regarding jQuery. I have a toggle function that is supposed to activate when clicking on a specific element - in this case, my logo image with the id of #logobutton. The toggle works great, but there's a problem. The an ...

What is the best way to organize Node/Express routes based on their type into different files?

My /router/index.js file is becoming too cluttered, and I want to organize my routes by group (user routes, post routes, gear routes) into separate files within /router/routes/. Here's what I currently have set up: app.js var express = require(&apos ...

JavaScript can be used to activate the onclick event

Is there a way to disable and then re-enable all buttons that share the same class name? I attempted the following code without success: let buttons = document.getElementsByClassName("btn-st"); for (let i = 0; i < buttons.length; i++) { b ...

How can I retrieve the attributes of multiple identical components within a webpage?

I've recently delved into learning Vue and decided to create a small application for adding fractions together. I have developed two main components: Fraction.vue and App.vue. The App.vue component contains multiple instances of the Fraction component ...

How can you use CommonsChunkPlugin in Webpack to bundle multiple entries into common chunks?

If I have two pages named Page1 and Page2, both utilizing libraries like jquery and backbone that I want to combine into a single file, with shared modules (excluding the vendors) in another file, here is the webpack configuration: Some example code here. ...

The GAS web application is experiencing issues with sorting dates correctly on the Javascript table

I have a food consumption log in a table that I need to sort. When I attempt to sort by the date column, I notice an issue with how it groups numbers together. For example, the sorting places all dates starting with 10 between 1 and 2, then all dates star ...

How to show the raw image content-type using Vue.js

When retrieving an image from a REST API through an HTTP GET with a request body, I have successfully verified the returned content using node.js and chai.js: expect(res).to.have.header('Content-Type', 'image/jpeg'); expect ...

The chosen index in the Material Stepper feature is experiencing a malfunction

I've been busy working on a Mat-Stepper, actually two of them. I have a component that contains two ng-templates set up like this: Question: Why is my selected index not functioning as expected? Am I missing something? I know you can define [selected ...

Utilizing JavaScript filtering logic in Angular Filter with AngularJS

This inquiry originates from this source Within the realm of Javascript, I have crafted a code to facilitate filtering, specifically showcasing elements from the array colors only if they correspond as values in cars. var colors = ["blue","red","pink","y ...

Unable to execute script tag on PHP page loading

When I make an AJAX request to fetch JavaScript wrapped in <script> tags that needs to be inserted on the current page, how can I ensure that the code executes upon insertion? Here's the snippet I'm using to add the code: function display ...