I haven't found anything regarding this problem yet so I'm asking here.
Our teacher gave us a RegEx exercise in JavaScript, we're supposed to apply these rules to user password creation:
- Password begins with the character P
- Password must contain one or more lowercase letters, one or more uppercase letters and one or more numbers
- Password must contain one * symbol
I tried to check whether the star is inside the text or not, by searching for P, then 1 or more symbols in [a-zA-Z0-9], then the * symbol and then 0 or more symbols in [a-zA-Z0-9] OR the other way around.
const pw_check = /P([a-zA-Z0-9]+\*[a-zA-Z0-9]*|[a-zA-Z0-9]*\*[a-zA-Z0-9]+)/;
console.log(pw_check.test("Ppassw1*")); // outputs true, shouldn't (it rather isn't wanted)
The issue with this is that it allows passwords with no capital letters (other than P). I'm guessing the same issue would arise if there weren't any digits or lowercase letters.
This is the closest I've got to solving this problem without the pattern getting too long. I've been pulling my hair out trying to solve this problem for a couple of hours now, reading JS regex documentation wasn't much helpful. Perhaps I'm just a little bit simple for this.
Any help is greatly appreciated, thank you in advance.