Download the PHP package youloge/webman.validate without Composer
On this page you can find all versions of the php package youloge/webman.validate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download youloge/webman.validate
More information about youloge/webman.validate
Files in youloge/webman.validate
Download youloge/webman.validate
More information about youloge/webman.validate
Files in youloge/webman.validate
Vendor youloge
Package webman.validate
Short Description Webman plugin youloge/webman.validate
License MIT
Package webman.validate
Short Description Webman plugin youloge/webman.validate
License MIT
Please rate this library. Is it a good library?
Informations about the package webman.validate
Youloge.validate Webman 高级表单验证器(PHP7.2+)
Webman 表单验证器是:Github Youloge.Tool 的子函数之一,如果安装了
webman.tool就不需要再安装webman.validate了。经过webman.validate过滤处理后的表单,基本可以达到入库要求,可以大大简化逻辑处理。[2.0.0+ 版本进行了重写 现在处理可以处理更加复杂的表单且不需要进行多次验证,在一个验证规则中即可处理任意复杂度的数据]
- [新]支持自定义匿名函数处理
- [新]支持数据流式流转处理
- 支持数据链式预处理处理
- 支持
对象和数组数据验证 - 支持自定义错误提示
- 支持
字段过滤,仅返回指定验证字段 - 可以对任意复杂表单进行处理过滤转化并合并结果
项目地址
Youloge.Validate Star 我 如果对你的项目有帮助 欢迎打赏~
- 2.0.1 [2026-03-07] 新增
流式处理 [M,N,Q],新增callable闭包自定义处理函数 - 1.4.2 [2025-11-11] 新增
sprintf,format规则,格式化字符串 - 1.4.0 [2025-10-25] 优化
required规则,允许0、'0'、false、[]、{} - 1.3.3 [2025-08-14] 新增
array和object数据类型 - 1.3.1 [2025-08-12] 默认数据类型与默认值:数据类型修复为一致
- 1.3.0 [2025-04-23] 添加
array_is_list函数,兼容到 php7.2+ - 1.2.8 [2025-03-20] 基本数据类型
int:100,float:1.02,bool:false,string:默认值提供默认值支持
安装使用
composer require youloge/webman.validate函数名称
useValidate()
使用说明
验证规则: |,:,,,#,[]
|分割多个规则:规则参数,多个参数用逗号分隔#自定义错误提示- $return = useValidate($params,$rules,$filter=true)
$params验证数据$rules验证规则$filter是否过滤数据,剔除规则之外的数据在返回 默认 true- 验证失败返回
['err'=>400,'msg'=>'错误提示'] - 验证成功返回 处理过后的数据
(filter)$params
参数说明
| 验证规则 | 说明 | 示例 | 规则类型 |
|---|---|---|---|
| required | 字段必填 | required | 基本处理 |
| int | 转为 int 类型 | int:10 | 基本处理 |
| bool | 转为 bool 类型 | bool:false | 基本处理 |
| float | 转为 float 类型 | float:1.2 | 基本处理 |
| string | 转为 string 类型 | int:string | 基本处理 |
| array | 转为 array 类型 | array:[] | 基本处理 |
| object | 转为 object 类型 | object:{} | 基本处理 |
| upper | 转为 大写字母 | upper | 基本处理 |
| lower | 转为 小写字母 | lower | 基本处理 |
| sprintf | 格式化字符串 | sprintf:%.2f | 基本处理 |
| format | 格式化字符串 | sprintf:%.4f | 基本处理 |
| join | 数组转字符串:可以指定连接符号,默认逗号 | join:@ | 基本处理 |
| trim | 去除参数两端空白符 | trim | 基本处理 |
| xss | 过滤特殊符号:支持不过滤(标签) | xss: | 基本处理 |
| html | 转义 HTML 标签 | html | 基本处理 |
| --- | --- | --- | --- |
| 验证是否为邮箱 | 常用验证 | ||
| mobile | 验证是否手机号(国内) | mobile | 常用验证 |
| url | 验证是否 URL 协议网址 | url | 常用验证 |
| ip | 验证是否 IP 地址 | ip | 常用验证 |
| date | 验证日期 | date:Y-m-D H:i:s | 常用验证 |
| idcard | 验证是否身份证(国内) | idcard | 常用验证 |
| regex | 正则验证 | regex:[a-zA-Z]{16} | 常用验证 |
| test | 正则验证 | regex:[a-zA-Z]{16} | 常用验证 |
| --- | --- | --- | --- |
| min | 参数最小值 | min:1 | 数字相关 |
| max | 参数最大值 | max:20 | 数字相关 |
| between | 参数取值范围 | between:1,100 | 数字相关 |
| --- | --- | --- | --- |
| start | 参数必须以%开头 | start:@ | 字符相关 |
| end | 参数必须以%结尾 | end:@qq.com | 字符相关 |
| digit | 参数必须为纯数字 | digit | 字符相关 |
| alpha | 参数必须为纯字母 | alpha | 字符相关 |
| alphanum | 参数必须为数字和数字 | alphanum | 字符相关 |
| length | 参数字符长度要在 min ~ max 之间 | length:12,14 | 字符相关 |
| len | 参数字符长度要在 min ~ max 之间 | length:12,14 | 字符相关 |
| --- | --- | --- | --- |
| in | 参数取值在之内 | between:a,b,c | 取值相关 |
| not | 参数取值在之外 | between:x,y,z | 取值相关 |
| count | 数组个数要在 min ~ max 之间 | count:1,6 | 取值相关 |
xss 过滤不仅会过滤 html 标签,还会过滤
',",;,--,%,_,(,), 可以防止Mysql 注入
- =============================
- = 过滤规则分为
预处理和验证规则新增闭包函数 - =============================
- =
基本处理:required int bool float string join trim upper lower sprintf format xss html - =
常用验证:email mobile url ip date time idcard regex test - =
数字相关:min max between - =
字符相关:start end digit alpha alphanum length - =
取值相关:in not count - =
闭包函数:function($field,$value){} - =============================
简单示例:
复杂示例:
请求数据:
验证规则:
流式处理
之前想对一个字段进行复杂操作,需要写第一步,第二步,第三步...,现在直接可以写成一维数组形式,规则:
['int:100'] 数组只有一个规则代表:数组按照改规则处理,当规则不止一个按照自动展开规则,再按照从左到右依次验证处理。
- 数组需要
1~6个标签 - 每个标签需要
至少2-20个字符 - 每个标签 是否包含违规字符
- 最终使用
,符号连接成字符串,正式项目表单会比这还要复杂,现在可以像以下这么写。
规则的配置是和输入表单 是对应的关系,验证器会预处理数据并交给后续过滤规则,所以碰到需要处理同一个键同时进行修改+验证的情况,进行多次拆分即可。
All versions of webman.validate with dependencies
PHP Build Version
Package Version
No informations.
The package youloge/webman.validate contains the following files
Loading the files please wait ...