|
@ -1,6 +1,7 @@ |
|
|
<?php |
|
|
<?php |
|
|
namespace wiggins\myProject\validators; |
|
|
namespace wiggins\myProject\validators; |
|
|
|
|
|
|
|
|
|
|
|
use E; |
|
|
use yii\validators\Validator; |
|
|
use yii\validators\Validator; |
|
|
use Yii; |
|
|
use Yii; |
|
|
|
|
|
|
|
@ -23,21 +24,24 @@ |
|
|
{ |
|
|
{ |
|
|
parent::init(); |
|
|
parent::init(); |
|
|
if ($this->message === null) { |
|
|
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} |
|
|
* {@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, []]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
?>
|
|
|
?>
|