PHPackages                             romeoz/rock-validate - 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. romeoz/rock-validate

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

romeoz/rock-validate
====================

Flexible validator for PHP with I18N.

0.12.1(9y ago)251.7k2[1 issues](https://github.com/romeOz/rock-validate/issues)6MITPHPPHP &gt;=5.4.0

Since Oct 26Pushed 9y ago4 watchersCompare

[ Source](https://github.com/romeOz/rock-validate)[ Packagist](https://packagist.org/packages/romeoz/rock-validate)[ RSS](/packages/romeoz-rock-validate/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (20)Used By (6)

Validator for PHP
=================

[](#validator-for-php)

[![Latest Stable Version](https://camo.githubusercontent.com/d5921683ee5493b27b819667d9bf13c5994c58962891f103226ab1f53d0789bc/68747470733a2f2f706f7365722e707567782e6f72672f726f6d654f7a2f726f636b2d76616c69646174652f762f737461626c652e737667)](https://packagist.org/packages/romeOz/rock-validate)[![Total Downloads](https://camo.githubusercontent.com/0b52b4ee4093002c5f1421887c420e13098a12f4b53ae4de32e92ab3c2fe54fc/68747470733a2f2f706f7365722e707567782e6f72672f726f6d654f7a2f726f636b2d76616c69646174652f646f776e6c6f6164732e737667)](https://packagist.org/packages/romeOz/rock-validate)[![Build Status](https://camo.githubusercontent.com/acd9679408c9a6c13991c37a8a9e2ce791fad6cf84321c666db4213889c9fbb5/68747470733a2f2f7472617669732d63692e6f72672f726f6d654f7a2f726f636b2d76616c69646174652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/romeOz/rock-validate)[![HHVM Status](https://camo.githubusercontent.com/7fd27041a2faae5f7f2e889cd27622297ba31fff0658057f9a022509ce7798de/687474703a2f2f6868766d2e683463632e64652f62616467652f726f6d656f7a2f726f636b2d76616c69646174652e737667)](http://hhvm.h4cc.de/package/romeoz/rock-validate)[![Coverage Status](https://camo.githubusercontent.com/27c6bb931a04ac1874ffda2603446377d93cac9b0efdb6e3314c99e4a2b681fe/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f726f6d654f7a2f726f636b2d76616c69646174652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/r/romeOz/rock-validate?branch=master)[![License](https://camo.githubusercontent.com/d602dd8e8a6ef3dd2e91ffce53d0b9a8955fa99e7c40ddb89d23023533b4f75d/68747470733a2f2f706f7365722e707567782e6f72672f726f6d654f7a2f726f636b2d76616c69646174652f6c6963656e73652e737667)](https://packagist.org/packages/romeOz/rock-validate)

Features
--------

[](#features)

- Supports large many validation rules (string, number, ctype, file, network)
- Validation of scalar variable and array (`attributes()`)
- **Output the list of errors in an associative array**
- **i18n support**
- **Hot replacement of placeholders for messages (`{{name}} must be valid`), as well messages**
- **Customization of validation rules**
- **Module for [Rock Framework](https://github.com/romeOz/rock)**

> Bolded features are different from [Respect/Validation](https://github.com/Respect/Validation).

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

[](#table-of-contents)

- [Installation](#installation)
- [Quick Start](#quick-start)
    - [Replacement a placeholder](#replacement-a-placeholder)
    - [i18n](#i18n)
    - [As array or object](#as-array-or-object)
- [Documentation](#documentation)
- [Demo](#demo)
- [Requirements](#requirements)

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

[](#installation)

From the Command Line:

```
composer require romeoz/rock-validate

```

In your composer.json:

```
{
    "require": {
        "romeoz/rock-validate": "*"
    }
}
```

Quick Start
-----------

[](#quick-start)

```
use rock\validate\Validate;

// Validation length from 10 to 20 characters inclusive + regexp pattern
$v = Validate::length(10, 20, true)->regex('/^[a-z]+$/i');
$v->validate('O’Reilly'); // output: false

$v->getErrors();
/*
output:

[
  'length' => 'value must have a length between 10 and 20',
  'regex' => 'value contains invalid characters'
]
*/

$v->getFirstError();
// output: value must have a length between 10 and 20
```

\####Replacement a placeholder

```
use rock\validate\Validate;

$v = Validate::length(10, 20, true)
            ->regex('/^[a-z]+$/i')
            ->setPlaceholders(['name' => 'username']);
$v->validate('O’Reilly'); // output: false

$v->getErrors();
/*
output:

[
  'length' => 'username must have a length between 10 and 20',
  'regex' => 'username contains invalid characters',
]
*/
```

\####i18n

```
use rock\validate\Validate;

$v = Validate::length(10, 20, true)->regex('/^[a-z]+$/i')->setLocale('ru');
$v->validate('O’Reilly'); // output: false

$v->getErrors();
/*
output:

[
  'length' => 'значение должно иметь длину в диапазоне от 10 до 20',
  'regex' => 'значение содержит неверные символы',
]
*/
```

\####As Array or Object

```
use rock\validate\Validate;

$input = [
    'username' => 'O’Reilly',
    'email' => 'o-reilly@site'
];
$attributes = [
  'username' => Validate::required()
      ->length(10, 20, true)
      ->regex('/^[a-z]+$/i')
      ->setPlaceholders(['name' => 'username']),

  'email' => Validate::required()->email()
];

$v = Validate::attributes($attributes);
$v->validate($input); // output false

$v->getErrors();
/*
output:

[
  'username' => [
    'length' => 'username must have a length between 10 and 20',
    'regex' => 'username contains invalid characters',
  ],
  'email' => [
    'email' => 'email must be valid email',
  ]
]
*/

$attribute = 'email';
$v->getFirstError($attribute);
// output: email must be valid
```

Documentation
-------------

[](#documentation)

- [Rules](https://github.com/romeOz/rock-validate/blob/master/docs/rules.md)
- [Custom messages, placeholders and templates](https://github.com/romeOz/rock-validate/blob/master/docs/custom-messages.md)
- [Custom rules](https://github.com/romeOz/rock-validate/blob/master/docs/custom-rules.md)

[Demo](https://github.com/romeOz/docker-rock-validate)
------------------------------------------------------

[](#demo)

- [Install Docker](https://docs.docker.com/installation/) or [askubuntu](http://askubuntu.com/a/473720)
- `docker run --name demo -d -p 8080:80 romeoz/docker-rock-validate`
- Open demo

Requirements
------------

[](#requirements)

- **PHP 5.4+**

License
-------

[](#license)

The Rock Validate is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

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

Recently: every ~116 days

Total

19

Last Release

3498d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/23c5d84a59845d751cb69f5469986579b9312c54c898b366fefdc05baaa80a9c?d=identicon)[romeOz](/maintainers/romeOz)

---

Top Contributors

[![romeOz](https://avatars.githubusercontent.com/u/3135712?v=4)](https://github.com/romeOz "romeOz (128 commits)")

---

Tags

validatorvalidationvalidate

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/romeoz-rock-validate/health.svg)

```
[![Health](https://phpackages.com/badges/romeoz-rock-validate/health.svg)](https://phpackages.com/packages/romeoz-rock-validate)
```

###  Alternatives

[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-validation)[wixel/gump

A fast, extensible &amp; stand-alone PHP input validation class that allows you to validate any data.

1.2k1.3M30](/packages/wixel-gump)[opis/json-schema

Json Schema Validator for PHP

64236.9M186](/packages/opis-json-schema)[sadegh19b/laravel-persian-validation

A comprehensive Laravel validation package for Persian text, numbers, dates, and Iranian national identifiers

18293.8k1](/packages/sadegh19b-laravel-persian-validation)[awurth/slim-validation

A wrapper around the respect/validation PHP validation library for easier error handling and display

65378.4k9](/packages/awurth-slim-validation)

PHPackages © 2026

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