Download the PHP package jeckleee/tools without Composer

On this page you can find all versions of the php package jeckleee/tools. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package tools

Jeckleee/Tools

一个 PHP 数据验证和工具库,提供符合直觉的链式调用验证器,让数据验证变得简单高效。

主要特性

安装

配置

验证规则总览

验证规则 说明 参数示例
基础验证
required 字段必填,可设置一个默认值 required('默认值')
ifExisted 字段存在时才验证,否则跳过 ifExisted()
requiredWith 当指定字段存在且不为空时,当前字段必填 requiredWith('email')
requiredWithout 当指定字段不存在或为空时,当前字段必填 requiredWithout('phone')
same 当前字段值必须与指定字段值相同 same('password')
different 当前字段值必须与指定字段值不同 different('old_password')
字符串验证
strTrim 去除字段两端的空格、制表符、换行符等 strTrim()
strLength 字段的值必须在指定范围的长度 strLength(3, 32)
strStartWith 字段的值必须以指定的字符串开始 strStartWith('http')
strEndWith 字段的值必须以指定的字符串结尾 strEndWith('.com')
strAlpha 字段的值只能由字母组成 strAlpha()
strAlphaNum 字段的值只能由字母和数字组成,true 时必须同时包含字母和数字 strAlphaNum(true)
strLowercase 将字段的值转换为小写 strLowercase()
strUppercase 将字段的值转换为大写 strUppercase()
数字验证
betweenNumber 字段的值必须在某两个数字区间(含) betweenNumber(1, 100)
cmpNumber 对字段进行比较,允许的符号: >, <, >=, <=, !=, = cmpNumber('>', 18)
isNumber 字段的值必须是数字(int 或 float,字符串数字也通过) isNumber()
isInt 字段的值必须是整数(int 类型或整数字符串,如 "123" 也通过) isInt()
isFloat 字段的值必须是小数,可限制小数位数 isFloat(2)
数组验证
inArray 字段的值必须在数组中 inArray([1,2,3])
notInArray 字段的值必须不在数组中 notInArray(['admin'])
isArray 字段的值必须是数组 isArray()
常用格式验证
isEmail 字段的值必须是邮箱 isEmail()
isMobile 字段的值必须是中国大陆手机号 isMobile()
isDateFormat 字段的值必须是指定格式的时间字符串 isDateFormat('Y-m-d')
isIdCard 字段的值必须是中国大陆身份证号 isIdCard()
isUrl 字段的值必须是网址 isUrl()
isIp 字段的值必须是 IP 地址(ipv4 或 ipv6) isIp('ipv4')
isBool 字段的值必须是布尔值 isBool()
isJson 字段的值必须是一个 json 字符串,true 时转为数组 isJson(true)
isBase64 字段的值必须是有效的Base64编码字符串 isBase64()
文件验证
isFile 文件校验,支持多种格式:
1. 原始 $_FILES 数组
2. Laravel 的 Illuminate\Http\UploadedFile 对象
3. Webman 的 support\UploadFile 对象
4. ThinkPHP 的 think\file\UploadedFile 对象
常见用法:
- isFile($_FILES, ['jpg','png'], 1024)
- isFile($request->file(), ['pdf'], 2048)
校验通过无返回值,失败则抛出异常
isFile($_FILES, ['jpg','png'], 1024)
其他验证
withRegex 使用正则表达式验证字段 withRegex('/^[a-z]+$/')
fun 使用自定义验证函数 fun(function($val){ return $val > 0; })

规则行为详解与注意事项


用法示例

1. 批量验证表单数据

2. 验证单个字段

3. 验证变量

4. 自定义验证规则

5. 条件必填验证

6. 字段值比较验证

7. 文件上传验证

8. JSON 字符串校验

9. Base64 编码校验

10. 浮点数校验

11. 数字比较

12. isInt/isNumber/isFloat 区别示例

13. isFile 返回值说明

14. 自定义函数校验

15. 字符串大小写转换


异常处理

自定义异常和错误码

错误返回模式

error_return_mode 只支持 immediate 和 collective,否则会抛出异常。


完整使用示例


工具函数

除了验证器,本工具还提供了一些常用的工具函数:

工具函数说明


注意事项

  1. 验证规则顺序:建议将 required 规则放在最前面,避免对空值进行不必要的验证。
  2. 错误消息:可以为每个规则自定义错误消息,提高用户体验。
  3. 性能考虑:使用 ifExisted 规则可以避免对不存在字段的验证。
  4. 文件验证:文件验证支持多种格式:
    • 原始 $_FILES 数组格式
    • Laravel 的 Illuminate\Http\UploadedFile 对象
    • Webman 的 support\UploadFile 对象
    • ThinkPHP 的 think\file\UploadedFile 对象
  5. 条件验证:合理使用 requiredWith 和 requiredWithout 可以处理复杂的表单逻辑。
  6. isInt/isNumber 区别:isInt 接受 int 类型 和 字符串整数 ;isNumber 可接受字符串数字 和 浮点数字符串。
  7. isFloat:可限制小数位数。
  8. isJson:true 时自动转为数组。
  9. 框架兼容性:可在 Laravel、Webman、ThinkPHP 等框架中使用。
  10. 配置函数依赖:如需自定义配置,需保证 config() 函数可用。

贡献

欢迎提交 Issue 和 Pull Request 来完善这个工具!

许可证

MIT License


All versions of tools with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
ext-mbstring Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jeckleee/tools contains the following files

Loading the files please wait ...