Click here to Skip to main content
14,324,857 members
Rate this:
Please Sign up or sign in to vote.
See more:
Here is a (naively) simple password checker that looks for between 3 and 6 characters and at least one number:

let password = "abc123";
let checkPass = /(?=\w{3,6})(?=\D*\d)/;
checkPass.test(password); // Returns true


why should i use the '\D*'?
can't understand the meaning of this character of this code..
with out this it would not work for example of: "bana12";

What I have tried:

code with out this character, and search for similar examples answers.
Posted
Updated 11-Mar-19 9:15am
v2
Comments
Member 14105304 11-Mar-19 15:01pm
   
comment:
for e.g : after 3 of \w would come 2 nums/digis, so after the D* (which mean the text before the nums) must come 2 nums.
Rate this:
Please Sign up or sign in to vote.

Solution 1

Open Expresso - you know, the app I suggested you install for both of your previous questions.
Now, paste the Regex into the "Regular Expression" pane:
(?=\w{3,6})(?=\D*\d)

Look to it's right at the "Regex Analyzer" pane. Expand all branches.
See how it explains what \D*\d does?

But that Regex is useless. It explicitly capture nothing, and wouldn't work if it did since it's trying to capture two suffixes and exclude them both...
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Quote:
Here is a (naively) simple password checker that looks for between 3 and 6 characters and at least one number:

You are misusing RegEx, RegEx is used to check if a string match a 'pattern'.
Things like URL, Email address, decimal number, car plates are following rules of construct, the pattern.
Use the Debuggex link to see a nice graph of the RegEx and to experiment with some candidate password to see what match and what don't.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx: Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
This site also show the Regex in a nice graph but can't test what match the RegEx: Regexper[^]

Nota: RegEx is a sophisticated subject reading documentation is mandatory to master it.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100