Вы не можете выбрать более 25 тем
Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
|
- <?php
-
- namespace App\Rules;
-
- use App\Models\Htpms\MstCustomer;
-
- class LoginPassword extends BaseRule
- {
-
- private string $message = '';
-
- private int $min = 8;
- private int $max = 20;
-
- /**
- * Create a new rule instance.
- *
- * @return void
- */
- public function __construct()
- {
- }
-
- public function check($value): bool
- {
- if (!$this->length($value)) return false;
- if (!$this->charactor($value)) return false;
- return true;
- }
-
- /**
- * Get the validation error message.
- *
- * @return string
- */
- public function message()
- {
- return $this->message;
- }
-
- private function length(string $value)
- {
- $len = strlen($value);
- if (8 <= $len && $len <= 20) {
- return true;
- } else {
- $this->message = "{$this->min}文字以上 {$this->max}以下で設定してください";
- return false;
- }
- }
-
- private function charactor(string $value)
- {
- if (preg_match("/^[a-zA-Z0-9@.\-]+$/", $value) === 0) {
- $this->message = "半角英数字と記号(@.-)のみ設定可能です。";
- return false;
- }
- return true;
- }
- }
|