PHPackages                             rougin/valla - 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. rougin/valla

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

rougin/valla
============

A simple validation package in PHP.

v0.1.1(4w ago)01.1kMITPHPPHP &gt;=5.3.0CI passing

Since May 16Pushed 4w agoCompare

[ Source](https://github.com/rougin/valla)[ Packagist](https://packagist.org/packages/rougin/valla)[ Docs](https://github.com/rougin/valla)[ RSS](/packages/rougin-valla/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (8)Versions (3)Used By (0)

Valla
=====

[](#valla)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ced1f697b61a526598f3750178361a8fe96e935ae242ce2478878a2972f94a97/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f7567696e2f76616c6c612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rougin/valla)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/rougin/valla/blob/master/LICENSE.md)[![Build Status](https://camo.githubusercontent.com/058a7927f62b3f5c92e5bdaff4666471104f0a4bbe0bf1885e97d205cc678ed4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f726f7567696e2f76616c6c612f6275696c642e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/rougin/valla/actions)[![Coverage Status](https://camo.githubusercontent.com/cceb2dfbd4ba9efa6f775a7f15ded7c8d4f421359c7552a9bb2dc2caff05ebe6/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f726f7567696e2f76616c6c613f7374796c653d666c61742d737175617265)](https://app.codecov.io/gh/rougin/valla)[![Total Downloads](https://camo.githubusercontent.com/07176be841f177c05a9fab0312a199c372455072b2bf2c6eb39c774905da76d9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f7567696e2f76616c6c612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rougin/valla)

A simple validation package for PHP inspired by [Valitron](https://github.com/vlucas/valitron).

```
use Rougin\Valla\Valid;

$data = array('name' => '', 'email' => 'not-an-email');

$valid = new Valid($data);

$valid->addRule('name', 'required');
$valid->addRule('email', 'required|email');

if (! $valid->passed())
{
    // "Name is required"
    echo $valid->firstError();
}
```

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

[](#installation)

Install the package using [Composer](https://getcomposer.org/):

```
$ composer require rougin/valla
```

Basic usage
-----------

[](#basic-usage)

The core of `Valla` is the `Valid` class. Create an instance with the data to validate, then add rules with `addRule()`:

```
use Rougin\Valla\Valid;

$data = array('age' => 'abc');
$data['email'] = 'not-an-email';
$data['name'] = '';

$valid = new Valid($data);

$valid->addRule('age', 'required|numeric');
$valid->addRule('email', 'required|email');
$valid->addRule('name', 'required');

if (! $valid->passed())
{
    $errors = $valid->getErrors();

    // "Age must be numeric"
    echo $valid->firstError();
}
```

### Setting labels

[](#setting-labels)

Labels provide user-friendly field names in error messages:

```
use Rougin\Valla\Valid;

$data = array('email' => 'not-an-email');

$valid = new Valid($data);

$labels = array('email' => 'Email Address');

$valid->setLabels($labels);

$valid->addRule('email', 'email');

if (! $valid->passed())
{
    // "Email Address is not a valid email address"
    echo $valid->firstError();
}
```

Adding custom rules
-------------------

[](#adding-custom-rules)

Custom rules can be added by implementing to `RuleInterface`:

```
namespace Rougin\Test\Rules;

use Rougin\Valla\RuleInterface;
use Rougin\Valla\Ruleset;

class Uppercase implements RuleInterface
{
    public function getError()
    {
        return 'must be uppercase';
    }

    public function getName()
    {
        return 'uppercase';
    }

    public function passed($value, array $data)
    {
        return strtoupper($value) === $value;
    }

    public function setValue(array $values)
    {
        return $this;
    }
}
```

To register the custom rule, add it to a `Ruleset` class then set it to the `Valid` class:

```
use Rougin\Test\Rules\Uppercase;
use Rougin\Valla\Valid;
use Rougin\Valla\Ruleset;

// Register the custom rule ---
$rules = new Ruleset;

$rules->addRule(new Uppercase);
// ----------------------------

// Inject the ruleset to check ---
$data = array('name' => 'Valla');

$valid = new Valid($data);

$valid->setRuleset($rules);
// -------------------------------

$valid->addRule('name', 'uppercase');

if (! $valid->passed())
{
    // "Name must be uppercase"
    echo $valid->firstError();
}
```

Using `Check` class
-------------------

[](#using-check-class)

The `Check` class provides a declarative, class-based approach to validation by defining rules and labels as properties. It wraps a `Valid` instance internally.

### Using labels, rules

[](#using-labels-rules)

The `$labels` property defines user-friendly names for the fields, while `$rules` specifies the validation rules:

```
use Rougin\Valla\Check;

class UserCheck extends Check
{
    protected $labels = array(
        'age' => 'Age',
        'email' => 'Email',
        'name' => 'Name',
    );

    protected $rules = array(
        'age' => 'required|numeric',
        'email' => 'required|email',
        'name' => 'required',
    );
}
```

### Validating data

[](#validating-data)

Once the `Check` class is created, validate an array of data using `valid()`:

```
$check = new UserCheck;

$data = array('name' => 'John');
$data['age'] = 20;
$data['email'] = 'john@example.com';

if (! $check->valid($data))
{
    echo $check->firstError();
}
```

### Dynamic labels, rules

[](#dynamic-labels-rules)

For more validation scenarios, the `labels` and `rules` methods can be overridden to define them dynamically:

```
use Rougin\Valla\Check;

class UserCheck extends Check
{
    /**
     * @return array
     */
    public function labels()
    {
        $labels = $this->labels;

        $labels['is_company'] = 'Is a Company?';

        return $labels;
    }

    /**
     * @param array $data
     *
     * @return array
     */
    public function rules(array $data)
    {
        $rules = $this->rules;

        if (array_key_exists('is_company', $data))
        {
            $rules['company_name'] = 'required';
        }

        return $rules;
    }
}
```

### Using PSR-7 requests

[](#using-psr-7-requests)

If using `ServerRequestInterface` from [PSR-7](https://www.php-fig.org/psr/psr-7/), the `Request` class provides a convenient way to validate request data:

```
use Rougin\Valla\Request;

class UserCheck extends Request
{
    /**
     * @var array
     */
    protected $aliases = array(

        'username' => 'name',
        'email_add' => 'email',
        'new_age' => 'age',

    );

    // ...
}
```

The `Request` class provides two methods for validation: `isParamsValid` for validating query parameters and `isParsedValid` for validating the parsed body:

```
$check = new UserCheck;

// Returns the "ServerRequestInterface" ---
$request = Http::getServerRequest();
// ----------------------------------------

// Checks against data from "getQueryParams" ---
if ($check->isParamsValid($request))
{
    // Query parameters are valid
}
// ---------------------------------------------

// Checks against data from "getParsedBody" ---
if ($check->isParsedValid($request))
{
    // Parsed body is valid
}
// --------------------------------------------
```

When an alias is specified, it will be used to look for the field in the `ServerRequestInterface` data. For example, if the request data contains a `username` field, it will be validated against the rules defined for the `name` field.

### Overriding `valid`

[](#overriding-valid)

When extending the `Request` class and overriding the `valid` method, the `setAlias` method must be called to apply the defined aliases:

```
use Rougin\Valla\Request;

class UserCheck extends Request
{
    // ...

    public function valid($data)
    {
        // Always include this if aliases are defined ---
        $data = $this->setAlias($data);
        // ----------------------------------------------

        if (! parent::valid($data))
        {
            return count($this->errors) === 0;
        }

        // Add extra custom validation conditions here

        return count($this->errors) === 0;
    }
}
```

Built-in rules
--------------

[](#built-in-rules)

Valla ships with 43 built-in rules, each pre-loaded in the default `Ruleset`:

### contains

[](#contains)

Checks that the value contains the given substring with non-string values fail automatically:

```
use Rougin\Valla\Valid;

$data = array('name' => 'Jane');

$valid = new Valid($data);

$valid->addRule('name', 'contains:Doe');

if (! $valid->passed())
{
    // "Name must contain Doe"
    echo $valid->firstError();
}
```

### creditCard

[](#creditcard)

Validates a credit card number using the Luhn algorithm with dashes and spaces stripped before checking:

```
use Rougin\Valla\Valid;

$data = array('card' => '123456789');

$valid = new Valid($data);

$valid->addRule('card', 'creditCard');

if (! $valid->passed())
{
    // "Card must be a valid credit card number"
    echo $valid->firstError();
}
```

### email

[](#email)

Validates a properly formatted email address with non-string values fail automatically:

```
use Rougin\Valla\Valid;

$data = array('email' => 'not-an-email');

$valid = new Valid($data);

$valid->addRule('email', 'email');

if (! $valid->passed())
{
    // "Email is not a valid email address"
    echo $valid->firstError();
}
```

### in

[](#in)

Checks that the value matches one of the listed values:

```
use Rougin\Valla\Valid;

$data = array('role' => 'guest');

$valid = new Valid($data);

$valid->addRule('role', 'in:admin,editor');

if (! $valid->passed())
{
    // "Role contains invalid value"
    echo $valid->firstError();
}
```

### instanceOf

[](#instanceof)

Validates that the value is an instance of the given class with non-object values fail automatically:

```
use Rougin\Valla\Valid;

$data = array('obj' => new \stdClass);

$valid = new Valid($data);

$valid->addRule('obj', 'instanceOf:\DateTime');

if (! $valid->passed())
{
    // "Obj must be an instance of 'DateTime'"
    echo $valid->firstError();
}
```

### lengthMax

[](#lengthmax)

Checks that the value does not exceed the given character length with non-string values fail automatically:

```
use Rougin\Valla\Valid;

$data = array('name' => 'too long');

$valid = new Valid($data);

$valid->addRule('name', 'lengthMax:5');

if (! $valid->passed())
{
    // "Name must not exceed 5 characters"
    echo $valid->firstError();
}
```

### lengthMin

[](#lengthmin)

Checks that the value meets the given minimum character length with non-string values fail automatically:

```
use Rougin\Valla\Valid;

$data = array('name' => 'Jo');

$valid = new Valid($data);

$valid->addRule('name', 'lengthMin:5');

if (! $valid->passed())
{
    // "Name must be at least 5 characters long"
    echo $valid->firstError();
}
```

### notIn

[](#notin)

Checks that the value does not match any of the listed values:

```
use Rougin\Valla\Valid;

$data = array('role' => 'admin');

$valid = new Valid($data);

$valid->addRule('role', 'notIn:admin,editor');

if (! $valid->passed())
{
    // "Role contains invalid value"
    echo $valid->firstError();
}
```

### numeric

[](#numeric)

Checks that the value is numeric:

```
use Rougin\Valla\Valid;

$data = array('age' => 'abc');

$valid = new Valid($data);

$valid->addRule('age', 'numeric');

if (! $valid->passed())
{
    // "Age must be numeric"
    echo $valid->firstError();
}
```

### required

[](#required)

Ensures the field is present and not empty with an optional strict mode rejecting only null:

```
use Rougin\Valla\Valid;

$data = array('name' => '');

$valid = new Valid($data);

$valid->addRule('name', 'required');

if (! $valid->passed())
{
    // "Name is required"
    echo $valid->firstError();
}
```

### requiredWith

[](#requiredwith)

Makes the field required when at least one of the listed fields is present and non-empty:

```
use Rougin\Valla\Valid;

$data = array('company_name' => '', 'is_company' => 'yes');

$valid = new Valid($data);

$valid->addRule('company_name', 'requiredWith:is_company');

if (! $valid->passed())
{
    // "Company_name is required"
    echo $valid->firstError();
}
```

### requiredWithout

[](#requiredwithout)

Makes the field required when at least one of the listed fields is absent or empty:

```
use Rougin\Valla\Valid;

$data = array('phone' => '');

$valid = new Valid($data);

$valid->addRule('phone', 'requiredWithout:email');

if (! $valid->passed())
{
    // "Phone is required"
    echo $valid->firstError();
}
```

### subset

[](#subset)

Checks that every item in the array belongs to the listed set with non-array values fail automatically:

```
use Rougin\Valla\Valid;

$data = array('options' => array('a', 'd'));

$valid = new Valid($data);

$valid->addRule('options', 'subset:a,b,c');

if (! $valid->passed())
{
    // "Options contains an item that is not in the list"
    echo $valid->firstError();
}
```

### accepted

[](#accepted)

Checks that the value is one of yes, on, 1, or true:

```
use Rougin\Valla\Valid;

$data = array('terms' => 'no');

$valid = new Valid($data);

$valid->addRule('terms', 'accepted');

if (! $valid->passed())
{
    // "Terms is not accepted"
    echo $valid->firstError();
}
```

### alpha

[](#alpha)

Checks that the value contains only alphabetic characters:

```
use Rougin\Valla\Valid;

$data = array('name' => '123');

$valid = new Valid($data);

$valid->addRule('name', 'alpha');

if (! $valid->passed())
{
    // "Name must contain only alphabetic characters"
    echo $valid->firstError();
}
```

### alphaNum

[](#alphanum)

Checks that the value contains only alpha-numeric characters:

```
use Rougin\Valla\Valid;

$data = array('name' => 'test!@#');

$valid = new Valid($data);

$valid->addRule('name', 'alphaNum');

if (! $valid->passed())
{
    // "Name must contain only alpha-numeric characters"
    echo $valid->firstError();
}
```

### array

[](#array)

Checks that the value is an array:

```
use Rougin\Valla\Valid;

$data = array('items' => 'string');

$valid = new Valid($data);

$valid->addRule('items', 'array');

if (! $valid->passed())
{
    // "Items must be an array"
    echo $valid->firstError();
}
```

### arrayHasKeys

[](#arrayhaskeys)

Checks that the array value contains all of the specified keys:

```
use Rougin\Valla\Valid;

$data = array('data' => array('a' => 1));

$valid = new Valid($data);

$valid->addRule('data', 'arrayHasKeys:a,b');

if (! $valid->passed())
{
    // "Data must contain the required keys"
    echo $valid->firstError();
}
```

### ascii

[](#ascii)

Checks that the value contains only ASCII characters:

```
use Rougin\Valla\Valid;

$data = array('name' => "J\xC3\xA1ne");

$valid = new Valid($data);

$valid->addRule('name', 'ascii');

if (! $valid->passed())
{
    // "Name must contain only ASCII characters"
    echo $valid->firstError();
}
```

### between

[](#between)

Checks that the numeric value falls between the given minimum and maximum:

```
use Rougin\Valla\Valid;

$data = array('age' => 25);

$valid = new Valid($data);

$valid->addRule('age', 'between:1,20');

if (! $valid->passed())
{
    // "Age must be between 1 and 20"
    echo $valid->firstError();
}
```

### boolean

[](#boolean)

Checks that the value is a boolean:

```
use Rougin\Valla\Valid;

$data = array('flag' => 'yes');

$valid = new Valid($data);

$valid->addRule('flag', 'boolean');

if (! $valid->passed())
{
    // "Flag must be a boolean"
    echo $valid->firstError();
}
```

### containsUnique

[](#containsunique)

Checks that the array value contains only unique values:

```
use Rougin\Valla\Valid;

$data = array('items' => array('a', 'b', 'a'));

$valid = new Valid($data);

$valid->addRule('items', 'containsUnique');

if (! $valid->passed())
{
    // "Items must contain unique values only"
    echo $valid->firstError();
}
```

### date

[](#date)

Checks that the value is a valid date string:

```
use Rougin\Valla\Valid;

$data = array('birthday' => 'not-a-date');

$valid = new Valid($data);

$valid->addRule('birthday', 'date');

if (! $valid->passed())
{
    // "Birthday must be a valid date"
    echo $valid->firstError();
}
```

### dateAfter

[](#dateafter)

Checks that the value is a date after the specified date:

```
use Rougin\Valla\Valid;

$data = array('date' => '2020-01-01');

$valid = new Valid($data);

$valid->addRule('date', 'dateAfter:2023-01-01');

if (! $valid->passed())
{
    // "Date must be a date after 2023-01-01"
    echo $valid->firstError();
}
```

### dateBefore

[](#datebefore)

Checks that the value is a date before the specified date:

```
use Rougin\Valla\Valid;

$data = array('date' => '2024-01-01');

$valid = new Valid($data);

$valid->addRule('date', 'dateBefore:2023-01-01');

if (! $valid->passed())
{
    // "Date must be a date before 2023-01-01"
    echo $valid->firstError();
}
```

### dateFormat

[](#dateformat)

Checks that the value matches the specified date format (e.g., `Y-m-d`):

```
use Rougin\Valla\Valid;

$data = array('date' => '01-01-2023');

$valid = new Valid($data);

$valid->addRule('date', 'dateFormat:Y-m-d');

if (! $valid->passed())
{
    // "Date must be a valid date format"
    echo $valid->firstError();
}
```

### different

[](#different)

Checks that the value is different from the value of another field:

```
use Rougin\Valla\Valid;

$data = array('a' => 'hello', 'b' => 'hello');

$valid = new Valid($data);

$valid->addRule('a', 'different:b');

if (! $valid->passed())
{
    // "A must be different from b"
    echo $valid->firstError();
}
```

### emailDNS

[](#emaildns)

Checks that the value is an email address with an active domain (MX record):

```
use Rougin\Valla\Valid;

$data = array('email' => 'test@nonexistent-domain.invalid');

$valid = new Valid($data);

$valid->addRule('email', 'emailDNS');

if (! $valid->passed())
{
    // "Email must be a valid email address with active domain"
    echo $valid->firstError();
}
```

### equals

[](#equals)

Checks that the value equals the value of another field:

```
use Rougin\Valla\Valid;

$data = array('a' => 'hello', 'b' => 'world');

$valid = new Valid($data);

$valid->addRule('a', 'equals:b');

if (! $valid->passed())
{
    // "A must be equal to b"
    echo $valid->firstError();
}
```

### integer

[](#integer)

Checks that the value is an integer with an optional strict mode:

```
use Rougin\Valla\Valid;

$data = array('age' => 'abc');

$valid = new Valid($data);

$valid->addRule('age', 'integer');

if (! $valid->passed())
{
    // "Age must be an integer"
    echo $valid->firstError();
}
```

### ip

[](#ip)

Checks that the value is a valid IP address:

```
use Rougin\Valla\Valid;

$data = array('ip' => 'not-an-ip');

$valid = new Valid($data);

$valid->addRule('ip', 'ip');

if (! $valid->passed())
{
    // "Ip must be a valid IP address"
    echo $valid->firstError();
}
```

### ipv4

[](#ipv4)

Checks that the value is a valid IPv4 address:

```
use Rougin\Valla\Valid;

$data = array('ip' => '::1');

$valid = new Valid($data);

$valid->addRule('ip', 'ipv4');

if (! $valid->passed())
{
    // "Ip must be a valid IPv4 address"
    echo $valid->firstError();
}
```

### ipv6

[](#ipv6)

Checks that the value is a valid IPv6 address:

```
use Rougin\Valla\Valid;

$data = array('ip' => '192.168.1.1');

$valid = new Valid($data);

$valid->addRule('ip', 'ipv6');

if (! $valid->passed())
{
    // "Ip must be a valid IPv6 address"
    echo $valid->firstError();
}
```

### length

[](#length)

Checks that the string length matches an exact value or falls between min and max:

```
use Rougin\Valla\Valid;

$data = array('name' => 'Jo');

$valid = new Valid($data);

$valid->addRule('name', 'length:5');

if (! $valid->passed())
{
    // "Name must be exactly 5 characters"
    echo $valid->firstError();
}
```

### lengthBetween

[](#lengthbetween)

Checks that the string length falls between the given min and max:

```
use Rougin\Valla\Valid;

$data = array('name' => 'too long');

$valid = new Valid($data);

$valid->addRule('name', 'lengthBetween:1,5');

if (! $valid->passed())
{
    // "Name must be between 1 and 5 characters"
    echo $valid->firstError();
}
```

### listContains

[](#listcontains)

Checks that the array value contains the specified item:

```
use Rougin\Valla\Valid;

$data = array('items' => array('a', 'b'));

$valid = new Valid($data);

$valid->addRule('items', 'listContains:c');

if (! $valid->passed())
{
    // "Items must contain the specified value"
    echo $valid->firstError();
}
```

### max

[](#max)

Checks that the numeric value does not exceed the given maximum:

```
use Rougin\Valla\Valid;

$data = array('age' => 25);

$valid = new Valid($data);

$valid->addRule('age', 'max:20');

if (! $valid->passed())
{
    // "Age must not exceed 20"
    echo $valid->firstError();
}
```

### min

[](#min)

Checks that the numeric value is at least the given minimum:

```
use Rougin\Valla\Valid;

$data = array('age' => 5);

$valid = new Valid($data);

$valid->addRule('age', 'min:10');

if (! $valid->passed())
{
    // "Age must be at least 10"
    echo $valid->firstError();
}
```

### optional

[](#optional)

Always passes regardless of the value, allowing a field to be optional:

```
use Rougin\Valla\Valid;

$data = array('field' => '');

$valid = new Valid($data);

$valid->addRule('field', 'optional');

// [NOTE] Optional rules always pass
$valid->passed();
```

### regex

[](#regex)

Checks that the value matches the given regular expression:

```
use Rougin\Valla\Valid;

$data = array('name' => 'hello');

$valid = new Valid($data);

$valid->addRule('name', 'regex:/^[0-9]+$/');

if (! $valid->passed())
{
    // "Name does not match the required pattern"
    echo $valid->firstError();
}
```

### slug

[](#slug)

Checks that the value is a valid slug (alpha-numeric, dashes, underscores):

```
use Rougin\Valla\Valid;

$data = array('slug' => 'not a slug!');

$valid = new Valid($data);

$valid->addRule('slug', 'slug');

if (! $valid->passed())
{
    // "Slug must be a valid slug"
    echo $valid->firstError();
}
```

### url

[](#url)

Checks that the value is a valid URL starting with http, https, or ftp:

```
use Rougin\Valla\Valid;

$data = array('link' => 'not-a-url');

$valid = new Valid($data);

$valid->addRule('link', 'url');

if (! $valid->passed())
{
    // "Link must be a valid URL"
    echo $valid->firstError();
}
```

### urlActive

[](#urlactive)

Checks that the value is a valid URL with an active domain (DNS record):

```
use Rougin\Valla\Valid;

$data = array('link' => 'http://nonexistent-domain.invalid');

$valid = new Valid($data);

$valid->addRule('link', 'urlActive');

if (! $valid->passed())
{
    // "Link must be a valid URL with active domain"
    echo $valid->firstError();
}
```

Migrating from Valitron
-----------------------

[](#migrating-from-valitron)

As this was inspired from [Valitron](https://github.com/vlucas/valitron), migrating to `Valla` is simple as changing its namespace and the class name. `Valla` provides the same `rule` method for mirroring Valitron's:

```
-use Valitron\Validator;
+use Rougin\Valla\Valid;

-$valid = new Validator($data);
+$valid = new Valid($data);

 $valid->rule('required', 'name');
 $valid->rule('min', 'age', 5);
 $valid->rule('required', array('name', 'email'));

 if (! $valid->validate())
 {
     print_r($valid->errors());
 }
```

Once migrated, update the said method to `addRule` with its required parameters:

```
-$valid->rule('required', 'name');
+$valid->addRule('name', 'required');
-$valid->rule('min', 'age', 5);
+$valid->addRule('age', 'min:5');
-$valid->rule('required', array('name', 'email'));
+$valid->addRule('name', 'required');
+$valid->addRule('email', 'required');
```

Warning

The `rule` method only accepts string rule names (e.g. `'required'`, `'min:5'`). Callable rules will not be supported. Kindly see [Adding custom rules](#adding-custom-rules) for how to create one.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](https://github.com/rougin/valla/blob/master/CHANGELOG.md) for more recent changes and latest updates.

Contributing
------------

[](#contributing)

See [CONTRIBUTING](https://github.com/rougin/valla/blob/master/CONTRIBUTING.md) on how to contribute to the project.

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE](https://github.com/rougin/valla/blob/master/LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance94

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity20

Early-stage or recently created project

 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 ~19 days

Total

2

Last Release

29d ago

### Community

Maintainers

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

---

Top Contributors

[![rougin](https://avatars.githubusercontent.com/u/6078637?v=4)](https://github.com/rougin "rougin (39 commits)")

---

Tags

php-validationphp-validatorphp-validationphp-validator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rougin-valla/health.svg)

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

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B4.0k](/packages/guzzlehttp-psr7)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[laminas/laminas-validator

Validation classes for a wide range of domains, and the ability to chain validators to create complex validation criteria

15848.2M222](/packages/laminas-laminas-validator)

PHPackages © 2026

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