Download the PHP package cube-group/myaf-validator without Composer
On this page you can find all versions of the php package cube-group/myaf-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package myaf-validator
Validator是一个简单的验证类
支持批量验证表单数据、自定义错误信息,简化大量的验证判断代码,使代码变得加简洁优雅!
快速使用
输出
快速验证单个规则
使用demo1 通过rule或rules添加验证规则
构造函数传入验证数据
输出
使用demo2 自定义错误信息
设置规则的的message属性 {field}最终替换为字段键, {value}替换为字段值
输出
使用demo3 设置字段标签
设置提示字段标签, 如name显示为名字, 通过构造方法传字段标签数组
输出
以下是目前支持的验证规则
- required 必传
- numeric 只能是数字
- alpha 只能包括英文字母(a-z)
- alphaNum 只能包括英文字母(a-z)和数字(0-9)
- slug 只能包括英文字母(a-z)、数字(0-9)、破折号和下划线
- bool 只能是true或false
- contains 必须包含指定字符串
- compare 对比验证
- length 字符串长度对比验证(基于compare验证)
- date 只能是日期格式
- dateAfter 日期必须在指定日期之后
- dateBefore 日期必须在指定日期之前
- same 必须和指定字段值相同
- diff 必须和指定字段值不同
- in 必须在指定范围
- notIn 必须不在指定范围
- numeric 必须是数字
- ip 必须是IP地址
- url 必须是URL地址
- tel 验证大陆电话
- carPlate 验证车牌号
- bankCard 验证银行卡号
- length 字符长度验证
- regex 匹配指定正则表达式
- func 使用函数或方法验证
- closure 使用闭包验证
- json 验证json格式
- intPositive 验证正整数
- domain 验证域名
验证规则使用Demo
required(验证必传)
设置skipEmpty属性为1可以跳过空验证,但是字段必传
json(验证json格式)
url(验证URL地址)
ip(验证IP地址)
email(验证邮箱)
numeric(验证数字)
alpha(验证英文字母)
alphaNum(验证英文字母+数字)
slug(英文字母+数字+破折号+下划线)
bool(验证必须是布尔值)
date(验证必须是时间日期格式)
tel(验证大陆电话)
mobile(验证手机号)
same(验证字段必须和另一个字段值相同)
diff(验证字段必须和另一个字段值不同)
compare(对比验证(支持> >= < <= == === != !===)
length(字符串长度对比验证,基于compare验证)
contains(必须包含acb)
in(必须在范围[1,2,3])
notIn(必须不在范围[1,2,3])
regex(正则验证)
func(函数或方法验证)
闭包验证(验证名字必须是helloWorld)
其他方法
设置字段标签
通过lables批量方法追加, 如果已经在值, 将覆盖旧值
调用rule后通过label方法添加
All versions of myaf-validator with dependencies
PHP Build Version
Package Version
Requires
cube-group/myaf-utils Version
*
The package cube-group/myaf-validator contains the following files
Loading the files please wait ....