pnhs/form_validator
Composer 安装命令:
composer require pnhs/form_validator
包简介
Validates forms and other strings
README 文档
README
English | Portuguese
Form Validator is an open source library for validating data received from users by forms or other means. The focus is to be simple and have an architecture compatible with the latest features of PHP.
We provide an example using "Form URL Encoded" (submission via simple HTML form) and a JSON example (submission via VUE-JS), we suggest you test both examples by doing Installation for testing, logo bellow
Help the Project to continue, donate a coffee!
or pix for brazilians: c6@seraf.im
Installation for testing
To test before including it in your project, open the terminal, prompt or powershell and run the commands below:
git clone https://github.com/seraf-im/formValidator.git
cd formValidator
composer install --no-dev
cd samples
php -S localhost:8000
Remembering that it is necessary that you have previously installed PHP and GIT.
Installation in your project
Composer
If you already know Composer (which is highly recommended), simply open the terminal, prompt or powershell in your project folder and type:
composer require pnhs/form_validator
How to use
That's the best part. It couldn't be simpler, see a basic example:
use Pnhs\FormValidator\Validator; $form = [ "username" => "nicolahsss", "password" => "password26" ]; $validator = new Validator($form); /* * required: Is required * no_empty: Cannot be sent blank * min_len: Minimum number of characters * max_len: Maximum number of characters */ $username = $validator->rules('username', 'required|no_empty|min_len:3|max_len:10'); $password = $validator->rules('password', 'required|no_empty|min_len:8'); //If there are errors, it returns json with the errors, if everything is fine, it returns NULL $errors = $validator->errors(); //See the result var_dump($username, $password, $errors ?? "OK");
Yes, just that! Just use the rules according to your need, if you wish you can contribute to the project by adding new rules. In the samples folder there are examples of using all the rules.
Supported Rules
Currently the Form Validator works with the following rules, remember you can always add more:
| Rule | Information | Details |
|---|---|---|
| array | ||
| date | Y-m-d standard date format | If your date has another pattern for example d/m/Y, just use this way "date:d/m/Y". The return always follows the Y-m-d pattern |
| datetime | Y-m-d H:i:s standard date format | If your date has another pattern for example d/m/Y H:i:s, just use this way "date:d/m/Y H:i:s". The return always follows the pattern Y-m-d H:i:s |
| decimal | 2 standard decimal places | If you want to use a number of decimal places other than 2, use "decimal: x" , changing x to the desired number of decimal places. |
| exact:x | To define the number of characters, change the x to the desired amount | |
| integer | ||
| max_len:x | ||
| min_len:x | ||
| For min_len and max_len , change x to the desired number of characters | ||
| no_empty | ||
| numeric | ||
| required | It can be empty, if you want the field to be required and not empty use both rules | |
| string | ||
Custom error code
You can use the # (hash) after the rule to enter the custom error code if you wish.
$validator->rules('username', 'required#2012|min:3#9999|max:10');
//In this example, if the value was not entered, the custom error code "2012" will be returned, if the number of characters is less than 3, the custom error "9999" will be returned.
Future rules
- username
- Password policy
- Document Validation*
- Phone validation*
Contribution
Every contribution is welcome. If you want to add new rules, feel free to explore the code, see how simple it is to integrate any rule into the library.
Translation
Also collaborate by including and correcting translations.
License
- MIT License
pnhs/form_validator 适用场景与选型建议
pnhs/form_validator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.17k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 06 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「form」 「validator」 「validation」 「form-validator」 「formulary」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pnhs/form_validator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pnhs/form_validator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pnhs/form_validator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Runn Me! Validation and Sanitization Library
Extension for Opis JSON Schema
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
A Laravel Filament Forms slug field.
Adds request-parameter validation to the SLIM 3.x PHP framework
A jQuery augmented PHP library for creating and validating HTML forms
统计信息
- 总下载量: 1.17k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-06-06