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
Leave A Comment
PHP blog