Regex for php, check if a variable has 1 uppercase, 1 small, 1 digit and 8 characters minimum

1

I have a project in php, I am quite new programming and I never touch that language, my question is basically what the title says, I need to see if a variable has 1 uppercase, 1 lowercase, 1 digit and 8 characters minimum I currently have this if

if(!preg_match('^(?=\w*\d)(?=\w*[A-Z])(?=\w*[a-z])\S{8,}$', $password)){
    /*
     *
     */
}
  • Warning: preg_match (): No ending delimiter '^' found in C: ... gives me this error
  • I guess that regular expression is not good for php, and I'm not finding the right way to do it
  • First I check in HTML 'pattern'=>'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$'
  • HTML control works fine, but I want to do it in Backend too.

    Thank you.

        
    asked by Javier Heisecke 12.07.2018 в 18:01
    source

    1 answer

    0

    Apparently you are not using delimiters for your regex, that is, you must enclose your regex expression with / or # or ~ , etc.

      

    When the PCRE functions are used, the pattern is required   is delimited by delimiters. A delimiter can be any   non-alphanumeric character, no backslash, or blank space.

    Your code should look like this:

    if(!preg_match('/^(?=\w*\d)(?=\w*[A-Z])(?=\w*[a-z])\S{8,}$/', $password)){
        /*
         *
         */
    }
    

    You can read more about Delimiters in PHP

        
    answered by 12.07.2018 / 18:15
    source