Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 601 Vote(s) - 3.4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters

#1
I want a regular expression to check that:

A password contains at least eight characters, including at least one number and includes both lower and uppercase letters and special characters, for example `#`, `?`, `!`.

It cannot be your old password or contain your username, `"password"`, or `"websitename"`

And here is my validation expression which is for eight characters including one uppercase letter, one lowercase letter, and one number or special character.

(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$"

How can I write it for **a password must be eight characters including one uppercase letter, one special character and alphanumeric characters**?
Reply

#2
I had some difficulty following the most popular answer for my circumstances. For example, my validation was failing with characters such as `;` or `[`. I was not interested in white-listing my special characters, so I instead leveraged `[^\w\s]` as a test - simply put - match non word characters (including numeric) and non white space characters. To summarize, here is what worked for me...


- at least `8` characters
- at least `1` numeric character
- at least `1` lowercase letter
- at least `1` uppercase letter
- at least `1` special character


----------


/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[^\w\s]).{8,}$/

[JSFiddle Link][1] - simple demo covering various cases


[1]:

[To see links please register here]

Reply

#3
(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+-]).{6}
Reply

#4
Just a small improvement for @anubhava's answer: Since special character are limited to the ones in the keyboard, use this for any special character:

`^(?=.*?[A-Z])(?=(.*[a-z]){1,})(?=(.*[\d]){1,})(?=(.*[\W]){1,})(?!.*\s).{8,}$`

This regex will enforce these rules:

- At least one upper case English letter
- At least one lower case English letter
- At least one digit
- At least one special character
- Minimum eight in length
Reply

#5
Import the JavaScript file `jquery.validate.min.js`.

You can use this method:

$.validator.addMethod("pwcheck", function (value) {
return /[\@\#\$\%\^\&\*\(\)\_\+\!]/.test(value) && /[a-z]/.test(value) && /[0-9]/.test(value) && /[A-Z]/.test(value)
});

1. At least one upper case English letter
2. At least one lower case English letter
3. At least one digit
4. At least one special character
Reply

#6
Regular expressions don't have an AND operator, so it's pretty hard to write a regex that matches valid passwords, when validity is defined by something AND something else AND something else...

But, regular expressions do have an OR operator, so just apply DeMorgan's theorem, and write a regex that matches invalid passwords:

Anything with less than eight characters **OR** anything with no numbers **OR** anything with no uppercase **OR** or anything with no lowercase **OR** anything with no special characters.

So:

^(.{0,7}|[^0-9]*|[^A-Z]*|[^a-z]*|[a-zA-Z0-9]*)$

If anything matches that, then it's an invalid password.
Reply

#7
According to your need this pattern should work just fine. Try this,

^(?=(.*\d){1})(.*\S)(?=.*[a-zA-Z\S])[0-9a-zA-Z\S]{8,}

Just create a string variable, assign the pattern, and create a boolean method which returns true if the pattern is correct, else false.

Sample:

String pattern = "^(?=(.*\d){1})(.*\S)(?=.*[a-zA-Z\S])[0-9a-zA-Z\S]{8,}";
String password_string = "Type the password here"

private boolean isValidPassword(String password_string) {
return password_string.matches(Constants.passwordPattern);
}

Reply

#8
In Java/Android, to test a password with at least one number, one letter, one special character in following pattern:

"^(?=.*[A-Za-z])(?=.*\\d)(?=.*[$@$!%*#?&])[A-Za-z\\d$@$!%*#?&]{8,}$"
Reply

#9
Try this one:

1. Minimum six characters
2. At least one uppercase character
3. At least one lowercase character
4. At least one special character

**Expression:**

"/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&.])[A-Za-z\d$@$!%*?&.]{6, 20}/"

Optional Special Characters:

1. At least one special character
2. At least one number
3. Special characters are optional
4. Minimum six characters and maximum 16 characters

**Expression:**

"/^(?=.*\d)(?=.*[a-zA-Z]).{6,20}$/"

If the min and max condition is not required then remove `.{6, 16}`

* **6** is minimum character limit
* **20** is maximum character limit
* **?=** means match expression

Reply

#10
Try this:

^.*(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])[a-zA-Z0-9@#$%^&+=]*$

This regular expression works for me perfectly.

function myFunction() {
var str = "c1TTTTaTTT@";
var patt = new RegExp("^.*(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])[a-zA-Z0-9@#$%^&+=]*$");
var res = patt.test(str);
console.log("Is regular matches:", res);
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through