Wrong output, I put a valid password and does not work

Asked

Viewed 33 times

0

return: string 'invalid password, only letters and are accepted numbers' (length=55)

class Validapass
{
    public function setValidapass($pass)
    {
        if (strlen($pass)<1)
            return 'escreva a password'; 
        else 
            if(!preg_match('/^[0-9a-z]$/i',$pass))
                return 'password invalida, apenas letras e são numeros aceites';
        else 
            return $pass;
    }
}
  • Is the password you entered just a letter or a number? More than that it will be invalid as the regular expression is waiting for only one character.

  • ja descobri! if(! preg_match('/ [0-9a-z]{4,20}$/i',$pass))

  • 1

    If the _ is also allowed, it is much easier to do /^\w{4,20}$/

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.