Blogger Information
Blog 64
fans 2
comment 3
visits 75555
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
验证器—2018年5月27日09:10:45
清雨的博客
Original
1071 people have browsed it

实例

<?php
namespace app\index\validate;
use think\Validate;

class User extends Validate
{
	protected $rule = [
		'name'  => 'require|max:25',
		'password' => 'number',
		'email' => 'email'
	];
	protected $message = [
		'name.require' => '姓名不能为空',
		'name.max'     => '姓名不能大于25个字符',
		'password.number'   => '密码必须是数字',
		'email'        => '邮箱格式错误'
	];
}

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

<?php
namespace app\index\controller;

use think\Collection;
use app\validate\User;
use think\Validate;

class Ver extends Collection
{
	public function demo()
	{
		$data =[
			'name' => '张飞',
			'password' => '12345678',
			'email'    => '38746471@qq.com'
		];
		$validate = new \app\index\validate\User;
		if (!$validate -> check($data)) {
			dump($validate -> getError());
		}else {
			return '验证通过';
		}
	}
}

运行实例 »

点击 "运行实例" 按钮查看在线实例

1.png

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post