承接 simfatic/boar 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

simfatic/boar

Composer 安装命令:

composer require simfatic/boar

包简介

Form validation library in PHP

README 文档

README

$v = Boar::create()
$v->field("name")->isRequired()->alphabetic()->maxLen(50)
$v->fields(["email", "address"])->areRequired()->maxLen(50)

$res = $v->validate($post_values)

if($res->hasErrors())
{
    echo json_encode($res->errors);    
}

Customizing the error message

$v->field("name")->maxLength(10)->withMessage("name should be shorter than {{max_length}}");

The message string is a template. {{field}} is replaced with the name of the field. For example, "{{field}} is required." when used with field address becomes "address is required". The message template can contain values from the specific validation as well. For example, max_length for MaxLength validation and min_length for MinLength validation.

All validations should be explicitly declared

$v->field("name")->maxLength(10)->alphabetic();

$res = $v->validate([]); //No Error. 

if name is a required field, should call isRequired() explicitly

$v->field("name")->isRequired()->maxLength(10)->alphabetic();

$res = $v->validate([]); //Error. 

Similarly,

$v->field("weight")->min(100);

$res = $v->validate(["weight"=>"not a number"]); //No Error. 

minimum validation will not validate for the data type. If the value is not number, it will silently ignore.

$v->field("weight")->isNumber()->min(100);

$res = $v->validate(["weight"=>"not a number"]); //Error. 

Keeping the granularity of the validation helps in predictable behavior and reduces ambiguity.

统计信息

  • 总下载量: 30
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-11-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固