seeds-std /
laravel-jp-validation-rules
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SeedsStd\JpValidationRules; |
||
| 4 | |||
| 5 | use Illuminate\Contracts\Validation\Rule; |
||
| 6 | |||
| 7 | class Hiragana implements Rule |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var array |
||
| 11 | */ |
||
| 12 | protected $configs; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Create a new rule instance. |
||
| 16 | * |
||
| 17 | * @param array $configs |
||
| 18 | * @return void |
||
| 19 | */ |
||
| 20 | public function __construct(array $configs = []) |
||
| 21 | { |
||
| 22 | $default_configs = []; |
||
| 23 | |||
| 24 | $this->configs = array_merge($default_configs, $configs); |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Determine if the validation rule passes. |
||
| 29 | * |
||
| 30 | * @param string $attribute |
||
| 31 | * @param mixed $value |
||
| 32 | * @return bool |
||
| 33 | */ |
||
| 34 | public function passes($attribute, $value) |
||
| 35 | { |
||
| 36 | return (bool)preg_match('/^(\xe3(\x81[\x81-\xbf]|\x82[\x80-\x93]|\x83\xbc))*$/', $value); |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Get the validation error message. |
||
| 41 | * |
||
| 42 | * @return string |
||
| 43 | */ |
||
| 44 | public function message() |
||
| 45 | { |
||
| 46 | return __('validation.hiragana'); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 47 | } |
||
| 48 | } |
||
| 49 |