1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace App\Validators\Rules;
- use Illuminate\Contracts\Validation\Rule;
- class UsernameRule 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)
- {
- //用户名验证,字母开头,包含6位以上数字与字母
- if (preg_match("/^(?=[a-zA-Z])(?!\d+)[A-Za-z0-9_.]{6,20}$/", $value)) {
- return true;
- }
- return false;
- }
- /**
- * Get the validation error message.
- *
- * @return string
- */
- public function message()
- {
- return '字母开头,包含6位以上数字、字母及大小写';
- }
- }
|