FyreValidation is a free, open-source validation library for PHP.

Overview

FyreValidation

FyreValidation is a free, validation library for PHP.

Table Of Contents

Installation

Using Composer

composer require fyre/validation

In PHP:

use Fyre\Validation\Rule;
use Fyre\Validation\Validator;

Validators

$validator = new Validator();

Add

Add a validation rule.

  • $field is a string representing the field name.
  • $rule is a Closure or a Rule representing the validation rule.
  • $options is an array containing options for the validation rule.
    • on is a string representing the type of validation the rule applies to, and will default to null.
    • message is a string representing the error message for the rule, and will default to null.
    • name is a string representing the name of the validation rule, and will default to null.
    • skipEmpty is a boolean indicating whether the rule should be skipped if the value is empty, and will default to true.
$validator->add($field, $rule, $options);

Clear

Clear all rules from the Validator.

$validator->clear();

Validate

Perform validation and return any errors.

  • $data is an array containing the data to validate.
  • $type is a string representing the type of validation, and will default to null.
$errors = $validator->validate($data, $type);

Rules

Alpha

Create an "alpha" Rule.

Rule::alpha();

Alpha Numeric

Create an "alpha-numeric" Rule.

Rule::alphaNumeric();

Ascii

Create an "ASCII" Rule.

Rule::ascii();

Between

Create a "between" Rule.

  • $min is a number representing the minimum value (inclusive).
  • $max is a number representing the maximum value (inclusive).
Rule::between($min, $max);

Boolean

Create a "boolean" Rule.

Rule::boolean();

Decimal

Create a "decimal" Rule.

Rule::decimal();

Date

Create a "date" Rule.

Rule::date();

DateTime

Create a "date/time" Rule.

Rule::dateTime();

Differs

Create a "differs" Rule.

  • $field is a string representing the other field to compare against.
Rule::differs($field);

Email

Create an "email" Rule.

Rule::email();

Empty

Create an "empty" Rule.

Rule::empty();

Equals

Create an "equals" Rule.

  • $value is the value to compare against.
Rule::equals($value);

Exact Length

Create an "exact length" Rule.

  • $length is a number representing the length.
Rule::exactLength($length);

Greater Than

Create a "greater than" Rule.

  • $min is the minimum value.
Rule::greaterThan($min);

Greater Than Or Equals

Create a "greater than or equals" Rule.

  • $min is the minimum value.
Rule::greaterThanOrEquals($min);

In

Create an "in" Rule.

  • $values is an array containing the values to compare against.
Rule::in($values);

Integer

Create an "integer" Rule.

Rule::integer();

Ip

Create an "IP" Rule.

Rule::ip();

Ipv4

Create an "IPv4" Rule.

Rule::ipv4();

Ipv6

Create an "IPv6" Rule.

Rule::ipv6();

Less Than

Create a "less than" Rule.

  • $max is the maximum value.
Rule::lessThan($max);

Less Than Or Equals

Create a "less than or equals" Rule.

  • $max is the maximum value.
Rule::lessThanOrEquals($max);

Matches

Create a "matches" Rule.

  • $field is a string representing the other field to compare against.
Rule::matches($field);

Max Length

Create a "maximum length" Rule.

  • $length is a number representing the maximum length.
Rule::maxLength($length);

Min Length

Create a "minimum length" Rule.

  • $length is a number representing the minimum length.
Rule::minLength($length);

Natural Number

Create a "natural number" Rule.

Rule::naturalNumber();

Regex

Create a "regular expression" Rule.

  • $regex is a string representing the regular expression.
Rule::regex($regex);

Required

Create a "required" Rule.

Rule::required();

Time

Create a "time" Rule.

Rule::time();

Url

Create a "URL" Rule.

Rule::url();

Error Messages

Custom error messages can be used by supplying the message property of the $options array to the Validator add method.

$validator->add('field', Rule::required(), [
    'message' => 'The field is required.'
]);

Alternatively, for custom validation callbacks, a string can be returned and that will be used as the error messages.

$validator->add('field', function($value) {
    if ($value) {
        return true;
    }

    return 'The field is required.';
});

If a custom error message is not supplied, the rule name will be used to retrieve a Lang value. The field placeholder can be used for the field name, and any arguments supplied to the rule will be available as numeric placeholders.

// language/en/Validation.php

return [
    'required' => 'The {field} is required.'
];

If no error message is available, the error message will simply be set to "invalid".

You might also like...
高性能的验证器组件(Validation),适用于 Hyperf 或 Laravel 框架,可获得数百倍的性能提升

验证器 简介 兼容 Hyperf/Laravel Validation 规则 部分场景可获得约 500 倍性能提升 验证器可多次复用不同数据,无状态设计 规则可全局复用 智能合并验证规则 安装 环境要求 PHP = 8.0 mbstring 扩展 ctype 扩展 安装命令 composer re

Extension for the Laravel validation class

Intervention Validation Intervention Validation is an extension library for Laravel's own validation system. The package adds rules to validate data l

Extra validation rules for dealing with images in Laravel 5.

Image-Validator Extra validation rules for dealing with images in Laravel 5. NOTE: As of Laravel version 5.2, there are now built-in validation rules

laminas-password-validator provides a validator for character-set based input validation.

laminas-password-validator laminas-password-validator provides a validator for character-set based input validation. Installation composer require pra

Laravel Validation Service

Laravel Validation Service Installation Add "prettus/laravel-repository": "1.1.*" to composer.json "prettus/laravel-validation": "1.1.*" Create a vali

🔒 Laravel validation rule that checks if a password has been exposed in a data breach.
🔒 Laravel validation rule that checks if a password has been exposed in a data breach.

🔒 Laravel Password Exposed Validation Rule This package provides a Laravel validation rule that checks if a password has been exposed in a data breac

PHP library for ArCaptcha. This package supports PHP 7.3+.

PHP ArCaptcha Library PHP library for ArCaptcha. This package supports PHP 7.3+. List of contents PHP ArCaptcha Library List of contents Installation

PHP library - Validators for standards from ISO, International Finance, Public Administrations, GS1, Manufacturing Industry, Phone numbers & Zipcodes for many countries

IsoCodes PHP library - Validators for standards from ISO, International Finance, Public Administrations, GS1, Book Industry, Phone numbers & Zipcodes

A simple filtering library for PHP

Filterus - A flexible PHP 5.3 filter package Filter Methods: Each filter class has two primary methods: $filter-filter($var) - returns a modified ver

Releases(v1.0.5)
Owner
Elusive
Just a guy who likes codin' stuff.
Elusive
Lightweight and feature-rich PHP validation and filtering library. Support scene grouping, pre-filtering, array checking, custom validators, custom messages. 轻量且功能丰富的PHP验证、过滤库。支持场景分组,前置过滤,数组检查,自定义验证器,自定义消息。

PHP Validate 一个简洁小巧且功能完善的php验证、过滤库。 简单方便,支持添加自定义验证器 支持前置验证检查, 自定义如何判断非空 支持将规则按场景进行分组设置。或者部分验证 支持在进行验证前对值使用过滤器进行净化过滤内置过滤器 支持在进行验证前置处理和后置处理独立验证处理 支持自定义每

Inhere 246 Jan 5, 2023
Valitron is a simple, elegant, stand-alone validation library with NO dependencies

Valitron: Easy Validation That Doesn't Suck Valitron is a simple, minimal and elegant stand-alone validation library with NO dependencies. Valitron us

Vance Lucas 1.5k Dec 30, 2022
[READ-ONLY] Validation library from CakePHP. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp

CakePHP Validation Library The validation library in CakePHP provides features to build validators that can validate arbitrary arrays of data with eas

CakePHP 39 Oct 11, 2022
Light and extendable schema validation library

Light PHP validation library For everyone who uses MongoDB or other NoSQL solution and cares about what client sends to his/her database and looking f

Alexander Serkin 43 Sep 28, 2022
An extensible validation library for your data with sane defaults.

Hird Hirds, also known as housecarls, was a gathering of hirdmen, who functioned as the king's personal guards during the viking age and the early mid

Asko Nõmm 13 Apr 23, 2022
File uploads with validation and storage strategies

Upload This component simplifies file validation and uploading. Usage Assume a file is uploaded with this HTML form: <form method="POST" enctype="mult

Brandon Savage 1.7k Dec 27, 2022
Abstracts HTTP request input handling, providing an easy interface for data hydration and validation

Linio Input Linio Input is yet another component of the Linio Framework. It aims to abstract HTTP request input handling, allowing a seamless integrat

Linio 41 Dec 12, 2021
One Line Validation, For CodeIgniter 4

One Line Validation (OLV) is a package made for CodeIgniter 4 to provide a fast and single line validation experience ideal for CDN and/or API services consuming the Validation System from CodeIgniter 4.

AJ Meireles 2 Sep 21, 2021
🔒 Laravel validation rule that checks if a password has been exposed in a data breach.

?? Laravel Password Exposed Validation Rule This package provides a Laravel validation rule that checks if a password has been exposed in a data breac

Jordan Hall 85 Apr 26, 2022
Validation rules for Money and Currency

money-validation-laravel Validation rules for Money and Currency Installation composer require brokeyourbike/money-validation-laravel Usage Package us

Ivan Stasiuk 1 Oct 25, 2021