Blogger Information
Blog 48
fans 3
comment 1
visits 37440
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
验证器——2018年5月25日
JackBlog
Original
662 people have browsed it



验证器类 实例

<?php
namespace app\validate;

use think\Validate;

class User extends Validate
{
	protected $rule = [
			'username'=>'require|length:6,20',
			'password'=>'require|length:6,14',
			'phone'=>'require|length:11|number',
			'email'=>'require|email'
	];
	protected $message=[
			'username.require'=>'用户名不得为空',
			'username.length'=>'用户名长度必须在6-20范围',
			'password.require'=>'密码不得为空',
			'password.length'=>'密码长度必须在6-20范围',
			'phone.require'=>'手机号码不得为空',
			'phone.length'=>'手机号码长度必须为11个字符',
			'phone.number'=>'手机号码必须为数字',
			'email.require'=>'邮箱不得为空',
			'email.email'=>'邮箱格式不正确',
	];
}

运行实例 »

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

实例

<?php
namespace app\index\controller;
use think\Controller;
use app\Validate\User;

class Verify extends Controller
{
	public function user()
	{
		$data = ['username'=>'zs84534344','password'=>'1me21234ss','phone'=>'13145206627','email'=>'97762821@qq.com'];
		$Validate = new User();
		$res = $Validate->check($data);
		if (!$res) {
			return $Validate->getError();
		}
		return 'success';
	}
}

运行实例 »

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


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