|
|
@ -1,7 +1,8 @@ |
|
|
|
<?php |
|
|
|
namespace wiggins\myProject\validators; |
|
|
|
|
|
|
|
use yii\validators\Validator; |
|
|
|
use E; |
|
|
|
use yii\validators\Validator; |
|
|
|
use Yii; |
|
|
|
|
|
|
|
/** |
|
|
@ -23,21 +24,24 @@ |
|
|
|
{ |
|
|
|
parent::init(); |
|
|
|
if ($this->message === null) { |
|
|
|
$this->message = Yii::t('yii', '{attribute}:{value} is not a valid hongkong phone number.'); |
|
|
|
$this->message = Yii::t('yii', '{attribute}({value})不是正确的香港电话号码.'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* {@inheritdoc} |
|
|
|
*/ |
|
|
|
public function validateAttribute($model, $attribute) |
|
|
|
protected function validateValue($value) |
|
|
|
{ |
|
|
|
echo "test"; |
|
|
|
if(!preg_match($this->pattern, $model->$attribute)) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
echo __FUNCTION__.PHP_EOL; |
|
|
|
if(!is_string($value)){ |
|
|
|
$valid=false; |
|
|
|
}elseif(!preg_match($this->pattern, $value)){ |
|
|
|
$valid=false; |
|
|
|
}else{ |
|
|
|
$valid=true; |
|
|
|
} |
|
|
|
return true; |
|
|
|
return $valid ? null : [$this->message, []]; |
|
|
|
} |
|
|
|
} |
|
|
|
?>
|