RegEx: determining the smallest sum of digits required in a character sequence

I'm trying to figure out a way to count the number of digits in a string that resembles a password.

Currently, I am using this regular expression:

^(?=.*[0-9]{3,})([a-zA-Z0-9_/+*.-]{6,})$

It works well when there are 3 consecutive digits, but not when they are scattered throughout the entire string.

I want to be able to detect if there are 3 digits in strings like these:

h123dasd 1hkh/23jd 1gvbn/*2fefse-

How can I achieve this?

Answer №1

If you're looking to verify the presence of at least 3 digits in your input, regardless of whether they are consecutive or not, you can use the following regular expression:

/^(?=(?:\D*\d){3,})[a-zA-Z0-9_/+*.-]{6,}$/

This regex pattern will ensure that there are at least 3 digits included in the input.

Check out the RegEx Demo here

Answer №2

I believe there is no necessity for a complex regex in this case - simply extract the digits from the string, combine the matches, and then verify the length. Here is an example:

str.match(/\d+/g).reduce((previous, current) => previous + current).length > 3;

Check out the DEMO here.

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

The d3.select function is failing to update the chart on the website

I am facing a challenge in updating data in a d3 chart with the click on an HTML object #id. After successfully coding it in jsfiddle, I encountered issues when implementing it on a web page. The scenario involves a simple leaflet map where the chart is d ...

Is it possible for a submission of a form to modify the content length header, resulting in the request failing?

Issue Description: After binding a submit event to an AJAX post request in order to send a predetermined key-value pair to a PHP script, the expected message indicating successful communication is not received. Despite the fact that the submit event trig ...

Resolving Text Animation Flickering Issues in CSS and React

After successfully creating this animation using CSS animations and React, I encountered a flickering issue. The cause of this problem is unclear to me, it could be due to my usage of setInterval or potential issues with the keyframes in my CSS animations. ...

How do I go about extracting and presenting the JSON data from the ESPN API?

In my current project, I am trying to utilize the jQuery library to work with API JSON data. Even though I am experienced in parsing JSON in PHP, I want to explore doing it with jQuery this time around. The goal is to extract information about each of the ...

The ng-message function appears to be malfunctioning

I am facing an issue with the angularjs ng-message not working in my code snippet. You can view the code on JSfiddle <div ng-app="app" ng-controller="myctrl"> <form name="myform" novalidate> error: {{myform.definition.$error ...

The Chrome Extension was denied from loading due to a violation of the specified Content Security Policy

I am encountering an issue while loading a Chrome Extension using React. Whenever I try to load it, the error message below pops up: Refused to load the script 'https://code.jquery.com/jquery-3.2.1.slim.min.js' because it violates the following ...

Beware, search for DomNode!

I attempted to create a select menu using material-ui and React const SelectLevelButton = forwardRef((props, ref) => { const [stateLevel, setStateLevel] = useState({ level: "Easy" }); const [stateMenu, setStateMenu] = useState({ isOpen ...

Sending the ID of a mapped button to a component

I need help with my React mapping function that displays a series of cards, each with its own button to open up a dialog box. Right now, I'm struggling to pass the unique ID from each object to the correct dialog box. Instead, all IDs are being passed ...

Can you explain the significance of the visitFunction error message?

When running [email protected] + [email protected] + [email protected] + [email protected], I encountered an error message. Can anyone help me understand what this error means? I am simply executing: res.render(view, response); Proper ...

How can I prevent right-clicking with Ctrl+LeftMouseClick in Firefox on MacOS?

I'm looking to implement a shortcut using Ctrl+LeftMouseClick in my React project. It functions perfectly on Chrome on my Mac, but in Firefox the shortcut initiates a right mouse click (event.button = 2). I believe this may be due to MacOS's Rig ...

Utilizing Angular: Integrating the Http response output into a map

I have a situation where I am making multiple HTTP calls simultaneously from my Angular application. The goal is to store the responses of these calls in a Map. data: Map<number, any> = new map<number,any>(); --------------------------------- ...

Tips for pulling out particular information from a string?

There is a text document that needs to be parsed. The objective is to extract the strings between "@5c00\n" and "@ffd2\n", as well as between "@ffd2\n" and "@". @5c00 81 00 00 5C B1 13 3E 01 0C 43 B1 13 A6 00 1C 43 B1 13 38 01 32 D0 10 00 ...

Creating a dynamic HIIT program with an autoplay feature for videos and images, using a jQuery/JavaScript slider "playlist" with the backend support of

I am currently exploring the idea of developing a countdown timer that incorporates videos. In order for this timer to function effectively, it must be able to retrieve data such as countdown time, break time, number of sets, and video (or images if no vid ...

Effortless Numerical Calculation for Trio Input Fields

I am in the process of setting up three numeric input fields that will automatically calculate and display results on the side. I am struggling with this task as I am not familiar with using ajax. Can someone assist me in implementing this functionality us ...

Trouble with Displaying 3rd Level JQuery Dropdown Menu

Currently working on implementing a 3 level dropdown feature. I have been using a third-party responsive menu in Opencart and it's been working well. You can see a demo of it here: Unfortunately, Opencart does not natively support 3 level categories, ...

Encountering net::ERR_CONTENT_LENGTH_MISMATCH error while using Datatable with AJAX, JSON, and JQUERY

I'm utilizing the Datatables library to create a table that auto-refreshes from a JSON feed. While it is functioning correctly, I am encountering an error message every time the data in the table changes: Failed to load resource: net::ERR_CONTENT_LEN ...

The function '.save' is not recognized by Mongoose

As a newcomer, I have been trying to understand the code in this calendar app that I created using express-generator. Everything seems to be working fine with connecting to MongoDB, but I am facing issues when trying to save a document. The section of my ...

Showing text in a textarea while maintaining formatting (such as using <br>)

Can someone help me with formatting a block of text like this: hello <br> how is your day <br> 123 To look like this: hello how is your day 123 I also need to display it in a textarea field. I attempted to do so using the following code: $ ...

Execute JavaScript code once the XMLHttpRequest has completed execution

I'm facing an issue where the JavaScript code is executing faster than the XMLHttpRequest. I am hesitant to resolve it using: setTimeout(function() {}, 100); Below is a snippet of my code: function change_country(id) { if (window.XMLHttpReques ...

Why does my script seem to be missing from this GET request?

Encountering an issue while setting up a page using npm and grunt. Request URL:http://localhost:9997/bower_components/requirejs/require.js Request Method:GET Status Code:404 Not Found The problematic html code is as follows: <script> ...