Skip to content

Rules

php

class Mobile 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)
    {
        preg_match('/^1\d{10}$/', $value, $match);
        return !empty($match);
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return '手机号:input 错误';
    }
}

// input是变量,输入
{
    "code": 0,
    "msg": "手机号123 错误",
    "data": ""
}

Lucking