| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace App\Rules;
- use Illuminate\Contracts\Validation\Rule;
- class IsPhone implements Rule
- {
- /**
- * Create a new rule instance.
- *
- * @return void
- */
- public function __construct()
- {
- //
- }
- /**
- * Determine if the validation rule passes.
- *
- * @param string $attribute
- * @param mixed $value
- * @return bool
- */
- public function passes($attribute, $value)
- {
- $callback = preg_replace('/[^0-9]/', '', $value);
- if (!preg_match("/^(02|0[3-6]\d|01(0|1|3|5|6|7|8|9)|070|080|007)\-?\d{3,4}\-?\d{4,5}$/", $callback) && !preg_match("/^(15|16|18)\d{2}\-?\d{4,5}$/", $callback)) {
- return false;
- }
- if (preg_match("/^(02|0[3-6]\d|01(0|1|3|5|6|7|8|9)|070|080)\-?0{3,4}\-?\d{4}$/", $callback)) {
- return false;
- }
- return true;
- }
- /**
- * Get the validation error message.
- *
- * @return string
- */
- public function message()
- {
- return ':attribute 은(는) 사용하실 수 없는 전화번호입니다.';
- }
- }
|