Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

61 line
1.2KB

  1. <?php
  2. namespace App\Rules;
  3. use App\Models\Htpms\MstCustomer;
  4. class LoginPassword extends BaseRule
  5. {
  6. private string $message = '';
  7. private int $min = 8;
  8. private int $max = 20;
  9. /**
  10. * Create a new rule instance.
  11. *
  12. * @return void
  13. */
  14. public function __construct()
  15. {
  16. }
  17. public function check($value): bool
  18. {
  19. if (!$this->length($value)) return false;
  20. if (!$this->charactor($value)) return false;
  21. return true;
  22. }
  23. /**
  24. * Get the validation error message.
  25. *
  26. * @return string
  27. */
  28. public function message()
  29. {
  30. return $this->message;
  31. }
  32. private function length(string $value)
  33. {
  34. $len = strlen($value);
  35. if (8 <= $len && $len <= 20) {
  36. return true;
  37. } else {
  38. $this->message = "{$this->min}文字以上 {$this->max}以下で設定してください";
  39. return false;
  40. }
  41. }
  42. private function charactor(string $value)
  43. {
  44. if (preg_match("/^[a-zA-Z0-9@.\-]+$/", $value) === 0) {
  45. $this->message = "半角英数字と記号(@.-)のみ設定可能です。";
  46. return false;
  47. }
  48. return true;
  49. }
  50. }