Magento Engineer
social
Journal

How to validate Alpha Numeric password validation ?

Must contain at least one number and one uppercase and lowercase letter and one special charectar, and at least 8 or more characters.

Method First:

<form action="#">
Password: <input type="password" name="password" id="password"
pattern="(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[^\w\s]).{8,}"
title="Must contain at least one number and one uppercase and lowercase letter and one special charectar, and at least 8 or more characters">
<input type="submit">
</form>

Method second through PHP validation :

$uppercase = preg_match('@[A-Z]@', $password); //uppercase
$lowercase = preg_match('@[a-z]@', $password); //lowercase
$number    = preg_match('@[0-9]@', $password); //numbers
$special   = preg_match('@[!@#$%^&*/()\-_=+{};:,<.>]@', $password); //special charectar

if(!$uppercase || !$lowercase || !$number || !$special || strlen($password) < 8) {
// tell the user something went wrong
}

Ad comes here
Comments
  • Rocky
    5 years ago

    Very helpfull

  • Jeniffer
    5 years ago

    Very nice Thank you

  • Abhi
    5 years ago

    Yes that is I want. thank you

Leave A Comment
PHP blog
Update Cookies Preferences