commit | author | age
|
90c639
|
1 |
<?php |
Z |
2 |
/** |
|
3 |
* @copyright ©2018 Lu Wei |
|
4 |
* @author Lu Wei |
|
5 |
* @link http://www.luweiss.com/ |
|
6 |
* Created by IntelliJ IDEA |
|
7 |
* Date Time: 2018/10/20 14:03 |
|
8 |
*/ |
|
9 |
|
|
10 |
|
|
11 |
namespace app\validators; |
|
12 |
|
|
13 |
|
|
14 |
use yii\validators\Validator; |
|
15 |
|
|
16 |
class VersionValidator extends Validator |
|
17 |
{ |
|
18 |
public function validateAttribute($model, $attribute) |
|
19 |
{ |
|
20 |
$value = $model->$attribute; |
|
21 |
$pattern = '/^\d*(\.\d*)*$/'; |
|
22 |
if ($value && !preg_match($pattern, $value)) { |
|
23 |
$model->addError($attribute, "{$model->getAttributeLabel($attribute)}格式不正确。"); |
|
24 |
} |
|
25 |
} |
|
26 |
} |