| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace App\Rules;
- use Illuminate\Contracts\Validation\Rule;
- class UppercaseLength implements Rule
- {
- private int $passwordUppercaseLength = 0;
- /**
- * Create a new rule instance.
- *
- * @return void
- */
- public function __construct()
- {
- // 비밀번호 유효성 검사 규칙 지정
- $this->passwordUppercaseLength = config('password_uppercase_length', 0);
- }
- /**
- * Determine if the validation rule passes.
- *
- * @param string $attribute
- * @param mixed $value
- * @return bool
- */
- public function passes($attribute, $value)
- {
- // 대문자 포함 여부
- return ($this->passwordUppercaseLength > 0 ? countUppercase($value) >= $this->passwordUppercaseLength : true);
- }
- /**
- * Get the validation error message.
- *
- * @return string
- */
- public function message()
- {
- return sprintf("비밀번호에는 %d개 이상의 대문자를 포함해야 합니다.", $this->passwordUppercaseLength);
- }
- }
|