0

I want to enter my password with special characters

capital letter, small letter, number and minimum 8 characters

I have this validator array and its need to also display message that password needs to be one capital , one small and minimum 8 characters.

public function admin_credential_rules(array $data){
    $messages = [
        'new_password.required' => "Zdejte nové heslo.",
        'password.required' => "Zadejte souÄasné heslo.",
    ];

    $validator = Validator::make($data, [
        'password' => 'required',
        'new_password' => 'required'
    ], $messages);

    return $validator;
}

how i can implement that. Thanks in advance!

executable
  • 3,365
  • 6
  • 24
  • 52
shahzad shah
  • 129
  • 18

1 Answers1

0

Try this

'password' => 'required|
               min:8|
               regex:/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\X])(?=.*[!$#%]).*$/|
               confirmed',

This will check for the one capital, one small letter, one numeric digit and one special character as well. Minimum number of character is 8. Hope it works

^ asserts position at start of the string
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Positive Lookahead (?=.{3,})
Assert that the Regex below matches
.{3,} matches any character (except for line terminators)
{3,} Quantifier — Matches between 3 and unlimited times, as many times as possible, giving back as needed (greedy)
Positive Lookahead (?=.*[a-zA-Z])
Assert that the Regex below matches
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below [a-zA-Z]
a-z a single character in the range between a (index 97) and z (index 122) (case sensitive)
A-Z a single character in the range between A (index 65) and Z (index 90) (case sensitive)
Positive Lookahead (?=.*[0-9])
Assert that the Regex below matches
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below [0-9]
0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
Positive Lookahead (?=.*[\d\X])
Assert that the Regex below matches
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below [\d\X]
\d matches a digit (equal to [0-9])
\X matches the character X literally (case sensitive)
Positive Lookahead (?=.*[!$#%])
Assert that the Regex below matches
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below [!$#%]
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
$ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)


          public function admin_credential_rules(array $data){
    $messages = [
        'new_password.required' => "Zdejte nové heslo.",
        'password.required' => "Zadejte souÄasné heslo.",
    ];

    $validator = Validator::make($data, [
        'password' => 'required|min:8|regex:/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\X])(?=.*[!$#%]).*$/|confirmed',
        'new_password' => 'required|min:8|regex:/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\X])(?=.*[!$#%]).*$/|confirmed',
    ], $messages);

    return $validator;
}
shahzad shah
  • 129
  • 18
Exterminator
  • 1,221
  • 7
  • 14