Jump to content

RegExp (Password Validation)


Raktim

Recommended Posts

I try a RegExp for validation which Must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters.

<input id="name" pattern="(?=.*\d)(?=.*[A-z])(?=.*[a-z]).{8,}"> 

Now I want to modify it which input must contain two number instead of one number. I tried that like...

<input id="name" pattern="(?=.*\d{2})(?=.*[A-z])(?=.*[a-z]).{8,}"> 

It works fine if I input two numeric digits Consecutive. Mean if I input 87aBcdfgf, then it is right. But 8aBcd7dfg input is wrong.

Please, modify my RegExp. which can take input 8aBcd7dfg like that.

Link to comment
Share on other sites

4 hours ago, Raktim said:

okay

Would something like this work?

(?=(.*\d){2,})(?=.*[A-Z])(?=.*[a-z]).{8,}

Test data:

aaBcde7fg - No Match (1 number)
aaBcd67fg - Match
87aBcdfgf - Match
8aBcd7dfg - Match

  • Thanks 1
Link to comment
Share on other sites

Sir, I want to make another regex that accepts any character at least 8 characters long except (0-9). How to write that?

I try it like...

[A-z!"#$%&'()*+,-.\/:;<=>?@[\]^_`{|}~]{8,}

Can I write this same regexp in another way?

Edited by Raktim
Link to comment
Share on other sites

Okay.

I already use the following pattern which takes At least two number, one lowercase letter one uppercase letter and at least 8 characters.

(?=(.*\d){2})(?=.*[A-z])(?=.*[a-z]).{8,}

Means, 4 characters (2 number + 1 lowercase + 1 uppercase letter)  are must need and other characters can be anything .

Now, I want that other charecter can be anyhthing except number. I replace * with [^0-9].

(?=(.*\d){2})(?=.*[A-Z])(?=.*[a-z])[^0-9]{8,}

But, it does't work. Why?

Edited by Raktim
Link to comment
Share on other sites

I also have another question

(?=(.*\d){2})(?=.*[A-Z])(?=.*[a-z])

If I use this pattern then I think it takes a total of 4 characters ( 2 number + 1 lowercase + 1 uppercase letter ) to match.

Tested Data:

Ab45 ->Not Match

a4F8-> Not Match

What actually happens? What is the meaning of this pattern?

Link to comment
Share on other sites

13 hours ago, justsomeguy said:

For your other pattern, I do get matches for those 2 strings.

 

But, those 2 string does not full match.

1 string only charecter 5 is matched and 2nd string only F8 are matched. But I want to do match the complete string. How to modify that?

 

Tested string.JPG

Edited by Raktim
Link to comment
Share on other sites

I want to make that input take only 2 number at least one lowercase, one uppercase and at least 8 characters except number.

I tried this pattern...

(?=(.*\d){2})(?=.*[A-z])(?=.*[a-z])[A-z!"#$%&'()*+,-.\/:;<=>?@[\]^_`{|}~]{8,}

But it totally fails. Then what should be my correct pattern to do that?

I want Like...

Abc4k9h2L ->FALSE

Abc4k9hL+ ->TRUE

Abc4l@s$kl4 ->TRUE

Edited by Raktim
Link to comment
Share on other sites

On 9/13/2019 at 8:03 PM, Raktim said:

But, those 2 string does not full match.

1 string only charecter 5 is matched and 2nd string only F8 are matched. But I want to do match the complete string. How to modify that?

You've gotta modify this regex so you're using the entire string that matches as follows.

(?=(.*\d){2})(?=.*[A-Z])(?=.*[a-z]).*

Does this work for this one?

 

On 9/13/2019 at 9:40 PM, Raktim said:

I want to make that input take only 2 number at least one lowercase, one uppercase and at least 8 characters except number.

I tried this pattern...


(?=(.*\d){2})(?=.*[A-z])(?=.*[a-z])[A-z!"#$%&'()*+,-.\/:;<=>?@[\]^_`{|}~]{8,}

But it totally fails. Then what should be my correct pattern to do that?

I want Like...

Abc4k9h2L ->FALSE

Abc4k9hL+ ->TRUE

Abc4l@s$kl4 ->TRUE

And for this one, I've done a negative lookahead, that if it matches more than 3 digits, it won't be valid.

^(?=(.*\d){2})(?=.*[A-Z])(?=.*[a-z])(?!(.*\d){3,}).*$

Does this work for this one?

Ab45 -> Match
a4F8 -> Match
aosjgHJ35 -> Match
JsOsm4Osmf6 -> Match
JsO2m4Os4f6 -> No match (3 numbers)

  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...