PHPackages                             sandromiguel/verum-php - 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. sandromiguel/verum-php

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

sandromiguel/verum-php
======================

Server-Side Form Validation Library for PHP

v2.4.0(1y ago)181672[1 issues](https://github.com/SandroMiguel/verum-php/issues)[2 PRs](https://github.com/SandroMiguel/verum-php/pulls)MITPHPPHP ^8.0CI failing

Since Jun 26Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/SandroMiguel/verum-php)[ Packagist](https://packagist.org/packages/sandromiguel/verum-php)[ Docs](https://github.com/SandroMiguel/verum-php)[ RSS](/packages/sandromiguel-verum-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (40)Used By (0)

[![Verum PHP](https://camo.githubusercontent.com/1060d138ddc306c493bd87b8442a383f0f32d4ce3320607b984be7a54fbb7582/687474703a2f2f73616e64726f6d696775656c2e636f6d2f686f73742f766572756d2d7068702e706e67)](https://camo.githubusercontent.com/1060d138ddc306c493bd87b8442a383f0f32d4ce3320607b984be7a54fbb7582/687474703a2f2f73616e64726f6d696775656c2e636f6d2f686f73742f766572756d2d7068702e706e67)

[![License](https://camo.githubusercontent.com/8d7d06f156679adc5a37f7db3f0327ed7aff7253358749c1cfbdfc805e29a700/68747470733a2f2f706f7365722e707567782e6f72672f73616e64726f6d696775656c2f766572756d2d7068702f6c6963656e7365)](//packagist.org/packages/sandromiguel/verum-php)[![Latest Stable Version](https://camo.githubusercontent.com/b5a87cb87914b3d98b2ff5f3288791c0ac180d61b3d6b3d4a5bb9f3cb0a60ad3/68747470733a2f2f706f7365722e707567782e6f72672f73616e64726f6d696775656c2f766572756d2d7068702f76)](//packagist.org/packages/sandromiguel/verum-php)[![Dependents](https://camo.githubusercontent.com/8af21ce3ccec2cb2bf7147820da2b9e16422828a9ed5cea167d868a3b017920e/68747470733a2f2f706f7365722e707567782e6f72672f73616e64726f6d696775656c2f766572756d2d7068702f646570656e64656e7473)](//packagist.org/packages/sandromiguel/verum-php)

Verum PHP
=========

[](#verum-php)

Verum PHP is a server-side validation library for PHP that allows you to validate arrays (with file support) with ease. It comes with custom error messages, rules, built-in translations, and zero dependencies.

**Server-Side Validation Library for PHP**

- Validate arrays (with file support)
- Custom error messages
- Custom rules
- Built-in translations
- Zero dependencies

Table of Contents
-----------------

[](#table-of-contents)

1. [Getting Started](#getting-started)
2. [Usage](#usage)
3. [Custom validations](#custom-validations)
4. [Available Rules](#available-rules)
5. [Contributing](#contributing)
6. [Questions](#questions)
7. [License](#license)

Getting Started
---------------

[](#getting-started)

### Installation

[](#installation)

Install Verum PHP with Composer

```
composer require sandromiguel/verum-php
```

### Usage

[](#usage)

#### Simple usage example

[](#simple-usage-example)

Validate a simple registration form (name, email and age)

```
use Verum\Validator;

$rules = [
    'name' => [
        'rules' => [
            'required',
        ],
    ],
    'email' => [
        'rules' => [
            'required',
            'email',
        ],
    ],
    'age' => [
        'rules' => [
            'numeric',
        ],
    ],
];

$validator = new Validator($_POST, $rules);

echo json_encode(
    [
        'valid'  => $validator->validate(),
        'errors' => $validator->getErrors(),
    ]
);
```

##### Valid form example

[](#valid-form-example)

Input:

```
[
    'name' => 'John Doe',
    'email' => 'johndoe@example.com',
    'age' => '20',
]
```

Output:

```
{
    "valid": true,
    "errors": []
}
```

##### Invalid form example

[](#invalid-form-example)

Input:

```
[
    'name' => '',
    'email' => 'some text',
    'age' => 'some text',
]
```

Output:

```
{
    "valid": false,
    "errors": {
        "name": {
            "label": null,
            "rules": {
                "required": "This field is required."
            }
        },
        "email": {
            "label": null,
            "rules": {
                "email": "This field must be a valid email address."
            }
        },
        "age": {
            "label": null,
            "rules": {
                "numeric": "This field must be numeric."
            }
        }
    }
}
```

#### Use `RuleEnum` class

[](#use-ruleenum-class)

You can use the `RuleEnum` class to access all rule names.

```
use Verum\Validator;
use Verum\Enum\RuleEnum;

$rules = [
    'name' => [
        'rules' => [
            RuleEnum::REQUIRED,
        ],
    ],
    ...
];
```

#### Specify the fields label (naming inputs)

[](#specify-the-fields-label-naming-inputs)

```
$rules = [
    'name' => [
        'label' => 'Name',
        'rules' => [
            RuleEnum::REQUIRED,
        ],
    ],
    ...
];
```

Output:

```
{
    ...
    "errors": {
        "name": {
            "label": "Name",
            "rules": {
                "required": 'The "Name" field is required.'
            }
        },
        ...
    }
}
```

#### Specify field labels for each language

[](#specify-field-labels-for-each-language)

```
$rules = [
    'name' => [
        'label' => [
            'en' => 'Name',
            'pt-pt' => 'Nome',
        ],
        'rules' => [
            RuleEnum::REQUIRED,
        ],
    ],
    ...
];
```

Output (pt-pt):

```
{
    ...
    "errors": {
        "name": {
            "label": "Nome",
            "rules": {
                "required": 'O campo "Nome" é obrigatório.'
            }
        },
        ...
    }
}
```

#### Specify the messages language

[](#specify-the-messages-language)

You can use some built-in translations:

- `'en'` -&gt; English (default)
- `'nl-nl'` -&gt; Dutch
- `'pt-pt'` -&gt; Portuguese-Portugal
- `'pt-br'` -&gt; Portuguese-Brazil

```
$validator = new Validator($_POST, $rules, 'pt-pt');
```

#### Specify the messages language using the `LangEnum` class

[](#specify-the-messages-language-using-the-langenum-class)

```
use Verum\Validator;
use Verum\Enum\LangEnum;

...

$validator = new Validator($_POST, $rules, LangEnum::PT_PT);
```

#### Specify a custom error message

[](#specify-a-custom-error-message)

- Useful to override the default error message.
- Useful for localization.

```
...
$validator = new Validator($_POST, $rules);
$validator->addSimpleCustomMessage('min_length', 'Min Length rule custom error message');
...
```

Output example:

```
{
    ...
    "errors": {
        "name": {
            "label": "Name",
            "rules": {
                "min_length": "Min Length rule custom error message"
            }
        },
        ...
    }
}
```

#### Specify a custom error message with placeholders

[](#specify-a-custom-error-message-with-placeholders)

```
...
$validator = new Validator($_POST, $rules);
$validator->addSimpleCustomMessage('min_length', 'Number of characters detected: {param:1}. Field name: "{param:2}".');
...
```

Output example:

```
{
    ...
    "errors": {
        "name": {
            "label": "Name",
            "rules": {
                "min_length": 'Number of characters detected: 5. Field name: "Name".'
            }
        },
        ...
    }
}
```

#### Specify a custom error message for fields with and without a label

[](#specify-a-custom-error-message-for-fields-with-and-without-a-label)

```
...
$validator = new Validator($_POST, $rules);
$validator->addCustomMessage(
    'required',
    'Custom error message with label for required rule. Label: {param:1}.',
    'Custom error message without label for required rule.'
);
...
```

Output - Field with label:

```
{
    ...
    "errors": {
        "name": {
            "label": "Name",
            "rules": {
                "required": 'Custom error message with label for required rule. Label: Name.'
            }
        },
        ...
    }
}
```

Output - Field without label:

```
{
    ...
    "errors": {
        "name": {
            "label": null,
            "rules": {
                "required": "Custom error message without label for required rule."
            }
        },
        ...
    }
}
```

#### Specify multiple custom error messages at once

[](#specify-multiple-custom-error-messages-at-once)

```
...
$validator = new Validator($_POST, $rules);
$validator->addCustomMessages(
    [
        'min_length' => 'Custom message for the "min_length" rule.',
        'required' => 'Custom message for the "required" rule.',
        // other messages ...
    ]
);
...
```

#### Specify multiple custom error messages at once for fields with and without a label

[](#specify-multiple-custom-error-messages-at-once-for-fields-with-and-without-a-label)

```
...
$validator = new Validator($_POST, $rules);
$validator->addCustomMessages(
    [
        'numeric' => [
            'withLabel' => 'Custom message with label for "numeric" rule. Label: {param:1}.',
            'withoutLabel' => 'Custom message without label for "numeric" rule.',
        ],
        'min_length' => [
            'withLabel' => 'Custom message with label for "min_length" rule. Label: {param:2}, value: {param:1}.',
            'withoutLabel' => 'Custom message without label for "min_length" rule. Value: {param:1}.',
        ],
        // other messages ...
    ]
);
...
```

#### Handling Multi-Name Fields

[](#handling-multi-name-fields)

With Verum PHP, you can handle multi-name fields more effectively. These are fields that include language identifiers or other variations in their names. For example, if you have fields like `title.en`, `title.pt`, `description.en`, and `description.pt`, you can specify rules for them using wildcards or by targeting specific fields.

##### Using Wildcards to Apply Rules to All Variants

[](#using-wildcards-to-apply-rules-to-all-variants)

You can define rules for all variants of a field using the `*` wildcard. For example:

```
$rules = [
    'title.*' => [
        'rules' => [
            RuleEnum::REQUIRED,
        ],
    ],
    'description.*' => [
        'rules' => [
            RuleEnum::REQUIRED,
            RuleEnum::MIN_LENGTH => 10,
        ],
    ],
];

$validator = new Validator($_POST, $rules);
// ...
```

Output example:

```
{
    "valid": false,
    "errors": {
        "title.en": {
            "label": null,
            "rules": {
                "required": "This field is required."
            }
        },
        "title.pt": {
            "label": null,
            "rules": {
                "required": "This field is required."
            }
        },
        "description.en": {
            "label": null,
            "rules": {
                "required": "This field is required.",
                "min_length": "This field must be at least 10 characters long."
            }
        },
        "description.pt": {
            "label": null,
            "rules": {
                "required": "This field is required.",
                "min_length": "This field must be at least 10 characters long."
            }
        }
    }
}
```

##### Validating Specific Variants

[](#validating-specific-variants)

If you only want to validate a specific variant of a field, you can target it directly. For example, to validate only the English title and make titles in other languages optional:

```
$rules = [
    'title.en' => [
        'rules' => [
            RuleEnum::REQUIRED,
        ],
    ],
];

$validator = new Validator($_POST, $rules);
// ...
```

Output example:

```
{
    "valid": false,
    "errors": {
        "title.en": {
            "label": null,
            "rules": {
                "required": "This field is required."
            }
        }
    }
}
```

This allows you to apply rules more precisely, ensuring flexibility in how multi-name fields are handled based on your application's needs.

Custom validations
------------------

[](#custom-validations)

You can use your custom validations and inject the error message.

```
if ($myCustomValidationFail) {
    $validator->addError(
        'someFieldName',
        'Some field name',
        ['no_duplicate' => 'A user already exists with that username')]
    );
    // ...
}
```

Available Rules
---------------

[](#available-rules)

1. [alpha](#alpha)
2. [alpha\_numeric](#alpha_numeric)
3. [between](#between)
4. [between\_length](#between_length)
5. [boolean\_value](#boolean_value)
6. [contains](#contains)
7. [date](#date)
8. [email](#email)
9. [equals](#equals)
10. [file\_max\_size](#file_max_size)
11. [file\_mime\_type](#file_mime_type)
12. [float\_number](#float_number)
13. [image\_max\_height](#image_max_height)
14. [image\_max\_width](#image_max_width)
15. [image\_min\_height](#image_min_height)
16. [image\_min\_width](#image_min_width)
17. [integer](#integer)
18. [ip](#ip)
19. [ipv4](#ipv4)
20. [ipv6](#ipv6)
21. [max](#max)
22. [max\_length](#max_length)
23. [min](#min)
24. [min\_length](#min_length)
25. [numeric](#numeric)
26. [regex](#regex)
27. [required](#required)
28. [slug](#slug)
29. [url](#url)

### alpha

[](#alpha)

Checks whether the value contains only alphabetic characters.

```
$rules = [
    'nickname' => [
        'label' => 'Nickname',
        'rules' => [
            RuleEnum::ALPHA,
        ],
    ],
];
```

Valuealphaalpha + required`null`✔️❌`''`✔️❌`'0'`❌❌`0`❌❌`false`❌❌`[]`❌❌`-1`❌❌`1`❌❌`true`❌❌`'text'`✔️✔️`'text with spaces'`❌❌### alpha\_numeric

[](#alpha_numeric)

Checks whether the value contains only alphanumeric characters.

```
$rules = [
    'nickname' => [
        'label' => 'Nickname',
        'rules' => [
            RuleEnum::ALPHA_NUMERIC,
        ],
    ],
];
```

Valuealpha\_numericalpha\_numeric + required`null`✔️❌`''`✔️❌`'0'`✔️✔️`0`✔️✔️`false`❌❌`[]`❌❌`-1`❌❌`1`✔️✔️`true`❌❌`'text'`✔️✔️`'text with spaces'`❌❌### between

[](#between)

Checks whether the value is between two values.

```
$rules = [
    'age' => [
        'label' => 'Age',
        'rules' => [
            RuleEnum::BETWEEN => [12, 29],
        ],
    ],
];
```

Valuebetween \[1, 10\]between \[1, 10\] + required`null`✔️❌`''`✔️❌`'0'`❌❌`0`❌❌`false`❌❌`[]`❌❌`-1`❌❌`1`✔️✔️`true`❌❌`'some text'`❌❌### between\_length

[](#between_length)

Checks whether the number of characters of the value is between min and max values.

```
$rules = [
    'nickname' => [
        'label' => 'Nickname',
        'rules' => [
            RuleEnum::BETWEEN_LENGTH => [3, 15],
        ],
    ],
];
```

Valuebetween\_length \[5,25\]between\_length \[5,25\] + required`null`✔️❌`''`✔️❌`'0'`❌❌`0`❌❌`false`❌❌`[]`❌❌`-1`❌❌`1`❌❌`12345`✔️✔️`true`❌❌`'text'`❌❌`'text with 23 characters'`✔️✔️### boolean\_value

[](#boolean_value)

Checks whether the value is a boolean value. Returns true for 1/0, '1'/'0', 'on'/'off', 'yes'/'no', true/false.

```
$rules = [
    'light' => [
        'label' => 'Light',
        'rules' => [
            RuleEnum::BOOLEAN_VALUE,
        ],
    ],
];
```

Valueboolean\_valueboolean\_value + required`null`✔️❌`''`✔️❌`'0'`✔️✔️`0`✔️✔️`false`✔️✔️`[]`❌❌`-1`❌❌`'1'`✔️✔️`1`✔️✔️`true`✔️✔️`'text'`❌❌`'on'`✔️✔️`'off'`✔️✔️`'yes'`✔️✔️`'no' `✔️✔️### contains

[](#contains)

Checks whether the value is in an array.

```
$rules = [
    'priority' => [
        'label' => 'Priority',
        'rules' => [
            RuleEnum::CONTAINS => ['low', 'high'],
        ],
    ],
];
```

Valuecontains \['low','high'\]contains \['low','high'\] + required`null`✔️❌`''`✔️❌`'0'`❌❌`0`❌❌`false`❌❌`[]`❌❌`-1`❌❌`1`❌❌`true`❌❌`'text'`❌❌`'low'`✔️✔️`'high'`✔️✔️### date

[](#date)

Checks whether the value is a valid date (Y-m-d) or a custom format.

#### Default format (Y-m-d)

[](#default-format-y-m-d)

```
$rules = [
    'dob' => [
        'label' => 'Date of birth',
        'rules' => [
            RuleEnum::DATE,
        ],
    ],
];
```

#### Custom format (e.g. d.m.Y)

[](#custom-format-eg-dmy)

```
$rules = [
    'dob' => [
        'label' => 'Date of birth',
        'rules' => [
            RuleEnum::DATE => ['d.m.Y'],
        ],
    ],
];
```

Valuedate \[Y-m-d\]date \[Y-m-d\] + required`null`✔️❌`''`✔️❌`'0'`❌❌`0`❌❌`false`❌❌`[]`❌❌`-1`❌❌`1`❌❌`true`❌❌`'text'`❌❌`'2020-09-30'`✔️✔️### email

[](#email)

Checks whether the value has a valid email format.

```
$rules = [
    'email' => [
        'label' => 'Email',
        'rules' => [
            RuleEnum::EMAIL,
        ],
    ],
];
```

Valueemailemail + required`null`✔️❌`''`✔️❌`'0'`❌❌`0`❌❌`false`❌❌`[]`❌❌`-1`❌❌`1`❌❌`true`❌❌`'text'`❌❌`'john@example.com'`✔️✔️### equals

[](#equals)

Checks whether the value is equal to another.

```
$rules = [
    'repeat_password' => [
        'label' => 'Repeat Password',
        'rules' => [
            RuleEnum::EQUALS => ['password'],
        ],
    ],
];
```

Comparison with `'text'`

Valueequalsequals + required`null`✔️❌`''`✔️❌`'0'`❌❌`0`❌❌`false`❌❌`[]`❌❌`-1`❌❌`1`❌❌`true`❌❌`'text'`✔️✔️`'another text'`❌❌### file\_max\_size

[](#file_max_size)

Checks whether the file size does not exceed a given value.

Enter a value in bytes.

```
$rules = [
    'profile_photo' => [
        'label' => 'Profile Photo',
        'rules' => [
            RuleEnum::FILE_MAX_SIZE => [102400],
        ],
    ],
];
```

Comparison with `102400` bytes

Valuefile\_max\_sizefile\_max\_size + required`null`✔️❌`50000`✔️✔️`150000`❌❌### file\_mime\_type

[](#file_mime_type)

Checks whether the file type is allowed.

```
$rules = [
    'profile_photo' => [
        'label' => 'Profile Photo',
        'rules' => [
            RuleEnum::FILE_MIME_TYPE => ['image/png', 'image/jpeg'],
        ],
    ],
];
```

Valuefile\_mime\_typefile\_mime\_type + required`null`✔️❌`image/png`✔️✔️`text/plain`❌❌### float\_number

[](#float_number)

Checks whether the value is a floating point number.

```
$rules = [
    'price' => [
        'label' => 'Price',
        'rules' => [
            RuleEnum::FLOAT_NUMBER,
        ],
    ],
];
```

Valuefloat\_numberfloat\_number + required`null`✔️❌`''`✔️❌`'0'`❌❌`0`❌❌`false`❌❌`[]`❌❌`-1`❌❌`1`❌❌`12345`❌❌`123.45`✔️✔️`true`❌❌`'text'`❌❌`'text with spaces'`❌❌### image\_max\_height

[](#image_max_height)

Checks whether the image height does not exceed a given value.

```
$rules = [
    'profile_photo' => [
        'label' => 'Profile Photo',
        'rules' => [
            RuleEnum::IMAGE_MAX_HEIGHT => [600],
        ],
    ],
];
```

Valueimage\_max\_heightimage\_max\_height + required`null`✔️❌500px✔️✔️1000px❌❌### image\_max\_width

[](#image_max_width)

Checks whether the image width does not exceed a given value.

```
$rules = [
    'profile_photo' => [
        'label' => 'Profile Photo',
        'rules' => [
            RuleEnum::IMAGE_MAX_WIDTH => [1000],
        ],
    ],
];
```

Valueimage\_max\_widthimage\_max\_width + required`null`✔️❌500px✔️✔️1500px❌❌### image\_min\_height

[](#image_min_height)

Checks whether the image height is not less than a given value.

```
$rules = [
    'profile_photo' => [
        'label' => 'Profile Photo',
        'rules' => [
            RuleEnum::IMAGE_MIN_HEIGHT => [300],
        ],
    ],
];
```

Valueimage\_min\_heightimage\_min\_height + required`null`✔️❌100px❌❌500px✔️✔️### image\_min\_width

[](#image_min_width)

Checks whether the image width is not less than a given value.

```
$rules = [
    'profile_photo' => [
        'label' => 'Profile Photo',
        'rules' => [
            RuleEnum::IMAGE_MIN_WIDTH => [500],
        ],
    ],
];
```

Valueimage\_min\_widthimage\_min\_width + required`null`✔️❌400px❌❌600px✔️✔️### integer

[](#integer)

Checks whether the value is integer.

```
$rules = [
    'distance' => [
        'label' => 'Distance',
        'rules' => [
            RuleEnum::INTEGER,
        ],
    ],
];
```

Valuenumericnumeric + required`null`✔️❌`''`✔️❌`'0'`❌❌`0`✔️✔️`false`❌❌`[]`❌❌`-1`✔️✔️`1`✔️✔️`true`❌❌`'text'`❌❌### ip

[](#ip)

Checks whether the value is a valid IP address.

```
$rules = [
    'ip' => [
        'label' => 'IP',
        'rules' => [
            RuleEnum::IP,
        ],
    ],
];
```

Valueipip + required`null`✔️❌`''`✔️❌`'0'`❌❌`0`❌❌`false`❌❌`[]`❌❌`-1`❌❌`1`❌❌`true`❌❌`'text'`❌❌`'10.10.10.10'`✔️✔️`'2607:f0d0:1002:51::4'`✔️✔️### ipv4

[](#ipv4)

Checks whether the value is a valid IPv4 address.

```
$rules = [
    'ipv4' => [
        'label' => 'IPv4',
        'rules' => [
            RuleEnum::IPV4,
        ],
    ],
];
```

Valueipv4ipv4 + required`null`✔️❌`''`✔️❌`'0'`❌❌`0`❌❌`false`❌❌`[]`❌❌`-1`❌❌`1`❌❌`true`❌❌`'text'`❌❌`'10.10.10.10'`✔️✔️`'2607:f0d0:1002:51::4'`❌❌### ipv6

[](#ipv6)

Checks whether the value is a valid IPv6 address.

```
$rules = [
    'ipv6' => [
        'label' => 'IPv6',
        'rules' => [
            RuleEnum::IPV6,
        ],
    ],
];
```

Valueipv6ipv6 + required`null`✔️❌`''`✔️❌`'0'`❌❌`0`❌❌`false`❌❌`[]`❌❌`-1`❌❌`1`❌❌`true`❌❌`'text'`❌❌`'10.10.10.10'`❌❌`'2607:f0d0:1002:51::4'`✔️✔️### max

[](#max)

Checks whether the value does not exceed a given value.

```
$rules = [
    'people' => [
        'label' => 'People',
        'rules' => [
            RuleEnum::MAX => [5],
        ],
    ],
];
```

Valuemaxmax + required`null`✔️❌`''`✔️❌`'0'`✔️✔️`0`✔️✔️`false`❌❌`[]`❌❌`-1`✔️✔️`1`✔️✔️`true`❌❌`'text'`❌❌`12345`❌❌`'12345'`❌❌### max\_length

[](#max_length)

Checks whether the number of characters of the value does not exceed a given value.

```
$rules = [
    'nickname' => [
        'label' => 'Nickname',
        'rules' => [
            RuleEnum::MAX_LENGTH => [2],
        ],
    ],
];
```

Valuemax\_lengthmax\_length + required`null`✔️❌`''`✔️❌`'0'`✔️✔️`0`✔️✔️`false`✔️✔️`[]`❌❌`-1`✔️✔️`1`✔️✔️`true`✔️✔️`'text'`❌❌`12345`❌❌`'12345'`❌❌### min

[](#min)

Checks whether the value is not less than a given value.

```
$rules = [
    'people' => [
        'label' => 'People',
        'rules' => [
            RuleEnum::MIN => [2],
        ],
    ],
];
```

Valueminmin + required`null`✔️❌`''`✔️❌`'0'`❌❌`0`❌❌`false`❌❌`[]`❌❌`-1`❌❌`1`❌❌`true`❌❌`'text'`❌❌`12345`✔️✔️`'12345'`✔️✔️### min\_length

[](#min_length)

Checks whether the number of characters of the value is not less than a given value.

```
$rules = [
    'nickname' => [
        'label' => 'Nickname',
        'rules' => [
            RuleEnum::MIN_LENGTH => [2],
        ],
    ],
];
```

Valuemax\_lengthmax\_length + required`null`✔️❌`''`❌❌`'0'`❌❌`0`❌❌`false`❌❌`[]`❌❌`-1`✔️✔️`1`❌❌`true`❌❌`'text'`✔️✔️`12345`✔️✔️`'12345'`✔️✔️### numeric

[](#numeric)

Checks whether the value is numeric.

```
$rules = [
    'age' => [
        'label' => 'Age',
        'rules' => [
            RuleEnum::NUMERIC,
        ],
    ],
];
```

Valuenumericnumeric + required`null`✔️❌`''`✔️❌`'0'`✔️✔️`0`✔️✔️`false`❌❌`[]`❌❌`-1`✔️✔️`1`✔️✔️`true`❌❌`'text'`❌❌### regex

[](#regex)

Checks whether the value matches a given regular expression.

```
$rules = [
    'path' => [
        'label' => 'Path',
        'rules' => [
            RuleEnum::REGEX => ['/\/client\/[0-9a-f]+$/'],
        ],
    ],
];
```

Validation with the `'/\/client\/[0-9a-f]+$/'` pattern

Valueregexregex + required`null`✔️❌`''`✔️❌`'0'`❌❌`0`❌❌`false`❌❌`[]`❌❌`-1`❌❌`1`❌❌`true`❌❌`'text'`❌❌`'/client/77c9e105d1f548b29958f0512967de87'`✔️✔️`'/client/invalid-uuid'`❌❌### required

[](#required)

Checks whether the value is not empty.

```
$rules = [
    'name' => [
        'label' => 'Name',
        'rules' => [
            RuleEnum::REQUIRED,
        ],
    ],
];
```

Valuerequired`null`❌`''`❌`'0'`✔️`0`✔️`false`✔️`[]`❌`-1`✔️`1`✔️`true`✔️`'some text'`✔️### slug

[](#slug)

Checks whether the value is a valid Slug (e.g. hello-world\_123).

```
$rules = [
    'slug' => [
        'label' => 'Slug',
        'rules' => [
            RuleEnum::SLUG,
        ],
    ],
];
```

Valueslugslug + required`null`✔️❌`''`✔️❌`'0'`❌❌`0`❌❌`false`❌❌`[]`❌❌`-1`❌❌`1`❌❌`true`❌❌`'text'`✔️✔️`'text with spaces'`❌❌`'hello-world_123'`✔️✔️### url

[](#url)

Checks whether the value is a valid URL.

```
$rules = [
    'url' => [
        'label' => 'URL',
        'rules' => [
            RuleEnum::URL,
        ],
    ],
];
```

Valueurlurl + required`null`✔️❌`''`✔️❌`'0'`❌❌`0`❌❌`false`❌❌`[]`❌❌`-1`❌❌`1`❌❌`true`❌❌`'text'`❌❌`'http://www.some-domain.com'`✔️✔️Contributing
------------

[](#contributing)

Want to contribute? All contributions are welcome. Read the [contributing guide](CONTRIBUTING.md).

Questions
---------

[](#questions)

If you have questions tweet me at [@sandro\_m\_m](https://twitter.com/sandro_m_m)or [open an issue](../../issues/new).

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

\*\*~ sharing is caring ~\*\*

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance68

Regular maintenance activity

Popularity23

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 93% 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 ~128 days

Recently: every ~76 days

Total

14

Last Release

474d ago

Major Versions

v1.0.0 → v2.0.02021-07-27

PHP version history (3 changes)v1.0.0PHP &gt;=7.2.0

v2.0.0PHP ^7.2 || ^8.0

v2.1.1PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6b082015ff3afef14c40ed5af8887ccaf378c6eaabd15aac38103ecdb5b0dc4f?d=identicon)[sandromiguel](/maintainers/sandromiguel)

---

Top Contributors

[![SandroMiguel](https://avatars.githubusercontent.com/u/6423157?v=4)](https://github.com/SandroMiguel "SandroMiguel (212 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (10 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (6 commits)")

---

Tags

phpphp-libraryvalidationvalidatorphpvalidatorvalidationPHP Library

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sandromiguel-verum-php/health.svg)

```
[![Health](https://phpackages.com/badges/sandromiguel-verum-php/health.svg)](https://phpackages.com/packages/sandromiguel-verum-php)
```

###  Alternatives

[blakvghost/php-validator

PHPValidator is a modern PHP library for data validation in your PHP applications. It provides a flexible and extensible way to validate data using predefined rules or by creating custom validation rules.

2524.2k2](/packages/blakvghost-php-validator)

PHPackages © 2026

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