我要输入特殊字符的密码
大写字母,小写字母,数字和至少8个字符
我有这个验证器数组,它还需要显示消息,密码必须是一个大写字母,一个小写且最少8个字符。
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;
}
我如何实现这一目标。 预先感谢!
答案 0 :(得分:0)
尝试一下
'password' => 'required|
min:8|
regex:/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\X])(?=.*[!$#%]).*$/|
confirmed',
这还将检查一个大写字母,一个小写字母,一个数字和一个特殊字符。字符的最小数量为8。希望它能起作用
^ 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;
}