@@ -20,11 +20,13 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | public static function format($phone) |
| 22 | 22 | { |
| 23 | - if (preg_match('/^(\d{1})(\d{3})(\d{3})(\d{2})(\d{2})$/', $phone, $matches)) |
|
| 24 | - return "+" . $matches[1] . ' (' . $matches[2] . ') ' . $matches[3] . "-" . $matches[4] . '-' . $matches[5]; |
|
| 23 | + if (preg_match('/^(\d{1})(\d{3})(\d{3})(\d{2})(\d{2})$/', $phone, $matches)) { |
|
| 24 | + return "+" . $matches[1] . ' (' . $matches[2] . ') ' . $matches[3] . "-" . $matches[4] . '-' . $matches[5]; |
|
| 25 | + } |
|
| 25 | 26 | |
| 26 | - if (preg_match('/^(\d{2})(\d{3})(\d{3})(\d{2})(\d{2})$/', $phone, $matches)) |
|
| 27 | - return "+" . $matches[1] . ' (' . $matches[2] . ') ' . $matches[3] . "-" . $matches[4] . '-' . $matches[5]; |
|
| 27 | + if (preg_match('/^(\d{2})(\d{3})(\d{3})(\d{2})(\d{2})$/', $phone, $matches)) { |
|
| 28 | + return "+" . $matches[1] . ' (' . $matches[2] . ') ' . $matches[3] . "-" . $matches[4] . '-' . $matches[5]; |
|
| 29 | + } |
|
| 28 | 30 | |
| 29 | 31 | return $phone; |
| 30 | 32 | } |
@@ -66,14 +66,17 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | protected function validateValue($value) |
| 68 | 68 | { |
| 69 | - if (is_array($value) || is_object($value)) |
|
| 70 | - return [Yii::t('yii', '{attribute} is invalid.'), []]; |
|
| 69 | + if (is_array($value) || is_object($value)) { |
|
| 70 | + return [Yii::t('yii', '{attribute} is invalid.'), []]; |
|
| 71 | + } |
|
| 71 | 72 | |
| 72 | - if (!is_numeric($value)) |
|
| 73 | - return [$this->formatError, []]; |
|
| 73 | + if (!is_numeric($value)) { |
|
| 74 | + return [$this->formatError, []]; |
|
| 75 | + } |
|
| 74 | 76 | |
| 75 | - if ((strlen(strval($value)) > 15) || (strlen(strval($value)) < 11)) |
|
| 76 | - return [$this->lengthError, []]; |
|
| 77 | + if ((strlen(strval($value)) > 15) || (strlen(strval($value)) < 11)) { |
|
| 78 | + return [$this->lengthError, []]; |
|
| 79 | + } |
|
| 77 | 80 | } |
| 78 | 81 | |
| 79 | 82 | /** |
@@ -83,8 +86,9 @@ discard block |
||
| 83 | 86 | */ |
| 84 | 87 | public function validate($value, &$error = null) |
| 85 | 88 | { |
| 86 | - if (!is_null($value) && !is_string($value) && !is_numeric($value)) |
|
| 87 | - return false; |
|
| 89 | + if (!is_null($value) && !is_string($value) && !is_numeric($value)) { |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 88 | 92 | $value = $this->clear($value); |
| 89 | 93 | $result = $this->validateValue($value); |
| 90 | 94 | if (!empty($result)) { |