Name Last Update
..
File.php Loading commit data...
Language.php Loading commit data...
Messages.php Loading commit data...
README.md Loading commit data...
Validator.php Loading commit data...

#Validator ##active_url

    Validator::make(
        ['url'=>'active_url']
    )

    Validator::make(
        ['url_str' => 'http://www.baidu.com'],
        ['url_str' => 'url']
    );
    字段值通过 PHP 函数 checkdnsrr 来验证是否为一个有效的网址。

##url

    Validator::make(
        ['url'=>'active_url']
    )

    Validator::make(
        ['url_str' => 'http://www.baidu.com'],
        ['url_str' => 'url']
    );
    网址格式不正确。

##after

    Validator::make(
        ['time'=>'after:date']
    )

    Validator::make(
        ['url_str' => '2015-04-01'],
        ['url_str' => 'after:date']
    );
    验证字段是否是在指定日期之后。这个日期将会使用 PHP strtotime 函数验证。

##alpha

    Validator::make(
        ['name'=>'alpha']
    )

    Validator::make(
        ['url_str' => 'asd'],
        ['url_str' => 'alpha']
    );
    字段仅全数为字母字串时通过验证。

##alpha_dash

    Validator::make(
        ['name'=>'alpha_dash']
    )
    Validator::make(
        ['url_str' => '..'],
        ['url_str' => 'alpha_dash']
    );
    字段值仅允许字母、数字、破折号(-)以及底线(_)

##alpha_num

    Validator::make(
        ['name'=>'alpha_num']
    )
    Validator::make(
        ['url_str' => '120l'],
        ['url_str' => 'alpha_num']
    );
    字段值仅允许字母、数字

##array

    Validator::make(
        ['list'=>'array']
    )
    Validator::make(
        ['url_str' => array()],
        ['url_str' => 'array']
    );
    字段值仅允许为数组

##between:min,max

    Validator::make(
        ['number'=>'between:min,max']
    )

    Validator::make(
        ['url_str' => 170000],
        ['url_str' => 'between:1,5']
    );
    字段值需介于指定的 min 和 max 值之间。字串、数值或是文件都是用同样的方式来进行验证。

##confirmed

    Validator::make(
        ['password_confirmation'=>'confirmed:password']
    )

    Validator::make(
        [
            'password' => 170000,
            'password_confirmation' => 1700001
        ],
        ['password_confirmation' => 'confirmed:password']
    );
    字段值需与对应的字段值 foo_confirmation 相同。例如,如果验证的字段是 password ,那对应的字段 password_confirmation 就必须存在且与 password 字段相符。

##date

    Validator::make(
        ['time'=>'date']
    )
    Validator::make(
        [
            'date_time' => '2015-05'
        ],
        ['date_time' => 'date']
    );
    字段值通过 PHP strtotime 函数验证是否为一个合法的日期

##digits:value

    Validator::make(
        ['time'=>'digits:value']
    )
    Validator::make(
        [
            'date_time' => 20
        ],
        ['date_time' => 'digits:2']
    );
    字段值需为数字且长度需为 value

##digits_between:min,max

    Validator::make(
        ['number'=>'digits_between:min,max']
    )
    Validator::make(
        [
            'date_time' => 200
        ],
        ['date_time' => 'digits_between:2,3']
    );
    字段值需为数字,且长度需介于 min 与 max 之间

##boolean

    Validator::make(
        ['is_open'=>'boolean']
    )
    Validator::make(
        [
            'date_time' => false
        ],
        ['date_time' => 'boolean']
    );
    字段必须可以转换成布尔值,可接受的值为 true, false, 1, 0, "1", "0"

##email

    Validator::make(
        ['email'=>'email']
    )
    Validator::make(
        [
            'date_time' => 'peter@gmail.com'
        ],
        ['date_time' => 'email']
    );
    字段值需符合 email 格式

##in

    Validator::make(
        ['code'=>'in:1,2,3,4,5']
    )
    Validator::make(
        [
            'date_time' => 1
        ],
        ['date_time' => 'in:1,2,3,4,5']
    );
    字段值需符合事先给予的清单的其中一个值

##not_in

    Validator::make(
        ['code'=>'in:1,2,3,4,5']
    )
    Validator::make(
        [
            'date_time' => 10
        ],
        ['date_time' => 'not_in:1,2,3,4,5']
    );
    字段值不得为给定清单中其一

##integer

    Validator::make(
        ['number'=>'integer']
    )

    Validator::make(
        [
            'date_time' => '1'
        ],
        ['date_time' => 'integer']
    );
    字段值需为一个整数值

##ip

    Validator::make(
        ['ip'=>'ip']
    )

    Validator::make(
        [
            'date_time' => '127.0.0.1'
        ],
        ['date_time' => 'ip']
    );
    字段值需符合 IP 位址格式

##max

    Validator::make(
        ['number'=>'max:value']
    )
    Validator::make(
        [
            'date_time' => '1'
        ],
        ['date_time' => 'max:1']
    );
    字段值需小于等于 value。字串、数字和文件则是判断 size 大小

##min

    Validator::make(
        ['number'=>'min:value']
    )
    Validator::make(
        [
            'date_time' => '1'
        ],
        ['date_time' => 'min:1']
    );
    字段值需大于等于 value。字串、数字和文件则是判断 size 大小

##numeric

    Validator::make(
        ['number'=>'numeric']
    )
    Validator::make(
        [
            'date_time' => '1'
        ],
        ['date_time' => 'numeric']
    );
    字段值需为数字

##regex:pattern

    Validator::make(
        ['number'=>'regex:pattern']
    )
    Validator::make(
        [
            'date_time' => '1'
        ],
        ['date_time' => 'regex:[\w]']
    );
    字段值需符合给定的正规表示式。

##required

    Validator::make(
        ['number'=>'required']
    )
    Validator::make(
        [
            'date_time' => '1'
        ],
        ['date_time' => 'required']
    );
    字段值为必填

##same:field

    Validator::make(
        ['number'=>'same:field']
    )
    Validator::make(
        [
            'date_time' => '1'
        ],
        ['date_time' => 'same:1']
    );
    字段值需与指定字段 field 等值

##size:value

    Validator::make(
        ['number'=>'size:value']
    )
    Validator::make(
        [
            'date_time' => '1'
        ],
        ['date_time' => 'size:1']
    );
    字段值的尺寸需符合给定 value 值。对于字串来说,value 为需符合的字串长度。对于数字来说,value 为需符合的整数值

##code

    判断是否有错误
    if ($validator->fails() == true) {

    }
    判断是否通过
    if ($validator->passes() == true) {

    }

    获取所有错误
    foreach ($validator->messages()->all() as $key => $val) {

    }
    获取指定错误
    $validator->messages()->get('email');