Skip to content

Instantly share code, notes, and snippets.

@madindo
Forked from Michael-Brooks/passwordValidation.php
Created January 28, 2022 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madindo/7e95475ee519aff56fc118a2f17e728a to your computer and use it in GitHub Desktop.
Save madindo/7e95475ee519aff56fc118a2f17e728a to your computer and use it in GitHub Desktop.
Laravel Password validation Regex (Contain at least one uppercase/lowercase letters and one number)
<?php
/*
* Place this with the rest of your rules.
* Doesn't need to be in an array as there are no pipes.
* Password is required with a minimum of 6 characters
* Should have at least 1 lowercase AND 1 uppercase AND 1 number
*/
$rules = [
'password' => 'required|min:6|regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$/'
];
/*
* Use this one if you also require at least one symbol.
* Needs to be in an array as it contains a pipe symbol.
* Password is required with a minimum of 6 characters
* Should have at least 1 lowercase AND 1 uppercase AND 1 number AND 1 symbol
*/
$rules = [
'password' => [
'required',
'min:6',
'regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*(_|[^\w])).+$/'
]
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment