34 lines
850 B
PHP
Executable File
34 lines
850 B
PHP
Executable File
<?php
|
|
|
|
namespace App\Rules;
|
|
|
|
use Closure;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
|
|
class PasswordRule implements ValidationRule
|
|
{
|
|
/**
|
|
* Run the validation rule.
|
|
*
|
|
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
|
*/
|
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
{
|
|
$isUppercase = preg_match('/[A-Z]/', $value);
|
|
$isNumber = preg_match('/[0-9]/', $value);
|
|
$isSymbol = preg_match('/\!|\@|\#|\$|\%|\^|\&|\*|\-/', $value);
|
|
|
|
if (!$isUppercase) {
|
|
$fail('Password must have capital letters.');
|
|
}
|
|
|
|
if (!$isNumber) {
|
|
$fail('Password must have number.');
|
|
}
|
|
|
|
if (!$isSymbol) {
|
|
$fail('Password must have symbol ! @ # $ % ^ & * -');
|
|
}
|
|
}
|
|
}
|