How do I modify this so it just requires a minimum Password length of 8 characters, but no maximum?
if (preg_match( (?=.{8,15}$) # Ensure Length is 8-15 Characters
(?=.*?[A-Z]) # Check for at least 1 Upper-Case
(?=.*?[a-z]) # Check for at least 1 Lower-Case
(?=.*?[0-9]) # Check for at least 1 Number
(?=.*?[\\~\\`\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\-\\+\\=\\{\\[\\}\\]\\|\\:\\;\\"\\'\\<\\,\\>\\.\\?\\/\\\\\\\\]) # Check for at least 1 Special-Character
){
Do I just changes things to this…
if (preg_match( (?=.{8, }$)
Thanks,
Debbie
I have been playing around and came up with this…
if (preg_match('~(?=.{8, }$) # Ensure Length is 8 or more Characters
(?=.*?[A-Z]) # Check for at least 1 Upper-Case
(?=.*?[a-z]) # Check for at least 1 Lower-Case
(?=.*?[0-9]) # Check for at least 1 Number
# Check for at least 1 Special-Character
(?=.*?[\\~\\`\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\-\\+\\=\\{\\[\\}\\]\\|\\:\\;\\"\\'\\<\\,\\>\\.\\?\\/\\\\\\\\])~', $trimmed['newPass1'])){
…but it is not working.
Debbie
I think you forgot to use the “x” mondifier… “~regex~x”
x (PCRE_EXTENDED[COLOR=#000000][FONT=verdana])
[/FONT][/COLOR]If this modifier is set, whitespace data characters in the pattern are totally ignored except when escaped or inside a character class, and characters between an unescaped # outside a character class and the next newline character, inclusive, are also ignored. This is equivalent to Perl’s /x modifier, and makes it possible to include commentary inside complicated patterns. Note, however, that this applies only to data characters. Whitespace characters may never appear within special character sequences in a pattern, for example within the sequence (?( which introduces a conditional subpattern.
I’m trying to piece together stuff from a simpler Regex that has been working…
I tried this, but still no go?!
if (preg_match('~(?x) # Comments Mode
^ # Beginning of String Anchor
(?=.{8, }$) # Ensure Length is 8 or more Characters
(?=.*?[A-Z]) # Check for at least 1 Upper-Case
(?=.*?[a-z]) # Check for at least 1 Lower-Case
(?=.*?[0-9]) # Check for at least 1 Number
# Check for at least 1 Special-Character
(?=.*?[\\~\\`\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\-\\+\\=\\{\\[\\}\\]\\|\\:\\;\\"\\'\\<\\,\\>\\.\\?\\/\\\\\\\\])
$ # End of String Anchor
~', $trimmed['newPass1'])){
Debbie
If all you want is a min of 8 alpha-numeric chars then
<?php
$password = "abc33";
$pattern = '/^[\\da-zA-Z]{8,}$/';
$isPasswordValid = preg_match($pattern, $password);
echo $isPasswordValid; //outputs 0 or 1
?>
The “x” goes at the very end of the regex, after “~”. Without it those comments and whitespace are part of the regex.