TP5.0.24 validation rules built max length error if the input validation problem Chinese

Validator needs to verify the maximum number of characters, such as

protected $rule = [
'name' => 'require|max:50'
];
protected $message = [
'Name.require' => 'classification must fill in the name of'
'Name.max' => 'category name can not exceed 50 characters'
];

 

'Name' => 'require | max: 50', have defined a maximum of 50 characters, but when the input Chinese characters say less than 20 characters in more than 50

Solution:

 

Modifying the underlying VALIDATE class thinkphp \ library \ think \ validate.php method of adding MAX UTF8 parameter, $ length = mb_strlen ((string) $ value, 'utf8');

Guess you like

Origin www.cnblogs.com/fogwang/p/12026962.html