PHPackages                             fyre/validation - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. fyre/validation

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

fyre/validation
===============

A validation library.

v7.0.2(7mo ago)0239↓83.3%1MITPHP

Since Jan 15Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/elusivecodes/FyreValidation)[ Packagist](https://packagist.org/packages/fyre/validation)[ RSS](/packages/fyre-validation/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (7)Versions (34)Used By (1)

FyreValidation
==============

[](#fyrevalidation)

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

Table Of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Methods](#methods)
- [Rules](#rules)
- [Error Messages](#error-messages)

Installation
------------

[](#installation)

**Using Composer**

```
composer require fyre/validation

```

In PHP:

```
use Fyre\Validation\Validator;
```

Basic Usage
-----------

[](#basic-usage)

- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).
- `$lang` is a [*Lang*](https://github.com/elusivecodes/FyreLang).

```
$validator = new Validator($container, $lang);
```

**Autoloading**

Any dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).

```
$validator = $container->use(Validator::class);
```

Methods
-------

[](#methods)

**Add**

Add a validation rule.

- `$field` is a string representing the field name.
- `$rule` is a *Closure* or a [*Rule*](#rules) 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](#error-messages) for the rule, and will default to *null*.
    - `name` is a string representing the name of the validation rule, and will default to *null*.

```
$validator->add($field, $rule, $options);
```

If using a *Closure* rule, the `$rule` should be expressed in the following format:

```
$rule = function(mixed $value, array $data, string $field): string|bool {
    // validation logic

    return true;
};
```

Any other arguments will be resolved from the [*Container*](https://github.com/elusivecodes/FyreContainer).

**Clear**

Clear all rules from the *Validator*.

```
$validator->clear();
```

**Get Field Rules**

Get the rules for a field.

- `$field` is a string representing the field name.

```
$rules = $validator->getFieldRules($field);
```

**Remove**

Remove a validation rule.

- `$field` is a string representing the field name.
- `$name` is a string representing the rule name.

```
$removed = $validator->remove($field, $name);
```

If the `$name` argument is omitted, all rules will be removed instead.

```
$validator->remove($field);
```

**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
-----

[](#rules)

```
use Fyre\Validation\Rule;
```

**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();
```

**Not Empty**

Create an "not empty" *Rule*.

```
Rule::notEmpty();
```

**Regex**

Create a "regular expression" *Rule*.

- `$regex` is a string representing the regular expression.

```
Rule::regex($regex);
```

**Required**

Create a "required" *Rule*.

```
Rule::required();
```

**Require Presence**

Create a "require presence" *Rule*.

```
Rule::requirePresence();
```

**Time**

Create a "time" *Rule*.

```
Rule::time();
```

**Url**

Create a "URL" *Rule*.

```
Rule::url();
```

Error Messages
--------------

[](#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(mixed $value): bool|string {
    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*](https://github.com/elusivecodes/FyreLang) 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*".

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance63

Regular maintenance activity

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~43 days

Recently: every ~16 days

Total

33

Last Release

226d ago

Major Versions

v2.0.4 → v3.02024-06-02

v3.0.5 → v4.02024-11-02

v4.0.1 → v5.02024-11-05

v5.0.2 → v6.02024-11-17

v6.0.7 → v7.02025-10-29

### Community

Maintainers

![](https://www.gravatar.com/avatar/fad81fd5941e3a637c8a5749d05ae3ed9314d5e2fee57f59c3d9ec3b41259c6b?d=identicon)[elusivecodes](/maintainers/elusivecodes)

---

Top Contributors

[![elusivecodes](https://avatars.githubusercontent.com/u/18050480?v=4)](https://github.com/elusivecodes "elusivecodes (27 commits)")

---

Tags

phprulesetvalidation

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/fyre-validation/health.svg)

```
[![Health](https://phpackages.com/badges/fyre-validation/health.svg)](https://phpackages.com/packages/fyre-validation)
```

###  Alternatives

[chaoswey/taiwan-id-validator

台灣身分證、統一編號驗證

319.9k](/packages/chaoswey-taiwan-id-validator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
