标签:attribute rule 用法 valid ThinkPHP alpha validate must
1.目录结构
2.控制器引用
protected $validate;
public function __construct()
{
$this->validate = new IndexValidate();//引入该控制器对应的验证规则
parent::__construct();
}
/*
*验证前端提交的post值
*
*/
public function Index()
{
$posts = $this->request->post();
$this->validate->scene("index")->check($posts) || $this->error($this->validate->getError(), [], 202);
}
3.validate文件
class IndexValidate extends Validate
{
//规则定义
protected $rule = [
"page" => "require|egt:1",// >=1
"per_page" => "require|elt:15|egt:1"// 1=<per_page<=15
];
//场景定义
protected $scene = [
"index" => ["page", "per_page"]
];
}
4.validate规则
protected static $typeMsg = [
'require' => ':attribute require',
'must' => ':attribute must',
'number' => ':attribute must be numeric',
'integer' => ':attribute must be integer',
'float' => ':attribute must be float',
'boolean' => ':attribute must be bool',
'email' => ':attribute not a valid email address',
'mobile' => ':attribute not a valid mobile',
'array' => ':attribute must be a array',
'accepted' => ':attribute must be yes,on or 1',
'date' => ':attribute not a valid datetime',
'file' => ':attribute not a valid file',
'image' => ':attribute not a valid image',
'alpha' => ':attribute must be alpha',
'alphaNum' => ':attribute must be alpha-numeric',
'alphaDash' => ':attribute must be alpha-numeric, dash, underscore',
'activeUrl' => ':attribute not a valid domain or ip',
'chs' => ':attribute must be chinese',
'chsAlpha' => ':attribute must be chinese or alpha',
'chsAlphaNum' => ':attribute must be chinese,alpha-numeric',
'chsDash' => ':attribute must be chinese,alpha-numeric,underscore, dash',
'url' => ':attribute not a valid url',
'ip' => ':attribute not a valid ip',
'dateFormat' => ':attribute must be dateFormat of :rule',
'in' => ':attribute must be in :rule',
'notIn' => ':attribute be notin :rule',
'between' => ':attribute must between :1 - :2',
'notBetween' => ':attribute not between :1 - :2',
'length' => 'size of :attribute must be :rule',
'max' => 'max size of :attribute must be :rule',
'min' => 'min size of :attribute must be :rule',
'after' => ':attribute cannot be less than :rule',
'before' => ':attribute cannot exceed :rule',
'afterWith' => ':attribute cannot be less than :rule',
'beforeWith' => ':attribute cannot exceed :rule',
'expire' => ':attribute not within :rule',
'allowIp' => 'access IP is not allowed',
'denyIp' => 'access IP denied',
'confirm' => ':attribute out of accord with :2',
'different' => ':attribute cannot be same with :2',
'egt' => ':attribute must greater than or equal :rule',
'gt' => ':attribute must greater than :rule',
'elt' => ':attribute must less than or equal :rule',
'lt' => ':attribute must less than :rule',
'eq' => ':attribute must equal :rule',
'unique' => ':attribute has exists',
'regex' => ':attribute not conform to the rules',
'method' => 'invalid Request method',
'token' => 'invalid token',
'fileSize' => 'filesize not match',
'fileExt' => 'extensions to upload is not allowed',
'fileMime' => 'mimetype to upload is not allowed',
标签:attribute,rule,用法,valid,ThinkPHP,alpha,validate,must 来源: https://blog.csdn.net/BugQian/article/details/120420125
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。