PHPackages                             renanhangai/validator - 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. renanhangai/validator

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

renanhangai/validator
=====================

Validate any php variable using a very simple sintax.

2.3.4(3y ago)1918[1 issues](https://github.com/renanhangai/libweb-validator/issues)[1 PRs](https://github.com/renanhangai/libweb-validator/pulls)1MITPHPCI passing

Since Nov 10Pushed 3w ago2 watchersCompare

[ Source](https://github.com/renanhangai/libweb-validator)[ Packagist](https://packagist.org/packages/renanhangai/validator)[ RSS](/packages/renanhangai-validator/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (3)Versions (19)Used By (1)

Validator
=========

[](#validator)

Validate objects against easily defined rules (See [API Reference](#api))

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

[](#installation)

```
composer require renanhangai/validator
```

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

[](#getting-started)

Simply validate some data

```
use libweb\Validator as v;

// Data to be validated
$data = array(
    "name" => "John Doe",
    "age"  => "45",
);
// Validate the data against the rule
$data = v::validate( $data, array(
    "name" => v::s(), //< String validator
    "age"  => v::i(), //< Integer validator
    "address?" => v::s(), //< Optional string validator
));

$data->name === "John Doe";
$data->age === 45;
$data->address === null;
```

Another Example
---------------

[](#another-example)

Simply validate some data

```
use libweb\Validator as v;

$data = array(
    "name" => "John Doe",
    "age"  => "45",
    "password" => "123456",
    "children" => array(
        array( "name" => "John Doe Jr", "age" => 15 ),
        array( "name" => "Mary Doe", "age" => 17 ),
    ),
);

$data = v::validate( $data, array(
    "name" => v::s(), //< String validator
    "age"  => v::i(), //< Integer validator
    "password" => v::s()->minlen( 6 ),
    "children" => v::arrayOf(array(
        "name" => v::s(),
        "age"  => v::i(),
    )),
));
```

Chainability
------------

[](#chainability)

Every method can be chained by using `->`

```
v::s()->str_replace( "foo", "bar" )->regex('/testbar$/')->minlen(10)
// Will pass on "mytestfoo", "another_testfoo", "testbar", "mytestbar"
```

API Reference
============================================

[](#api-reference)

Summary
-------

[](#summary)

- Type validators
    - [`any()`](#api-any)
    - [`arrayOf($rule)`](#api-array-of)
    - [`boolval()`](#api-boolval)
    - [`b()`](#api-boolval)
    - [`date($format = null, $out = null)`](#api-date)
    - [`decimal($digits, $decimal, $decimalSeparator = null, $thousandsSeparator = null)`](#api-decimal)
    - [`floatval($decimal = null, $thousands = null, $asString = false)`](#api-floatval)
    - [`f($decimal = null, $thousands = null, $asString = false)`](#api-floatval)
    - [`instanceOf($type)`](#api-instance-of)
    - [`intval()`](#api-intval)
    - [`i()`](#api-intval)
    - [`obj($definition)`](#api-obj)
    - [`strval($trim = true)`](#api-strval)
    - [`s($trim = true)`](#api-strval)
- String rules
    - [`blacklist($chars)`](#api-blacklist)
    - [`len($min, $max = null)`](#api-len)
    - [`minlen($min)`](#api-minlen)
    - [`preg_replace($search, $replace)`](#api-preg-replace)
    - [`regex($pattern)`](#api-regex)
    - [`str_replace($search, $replace)`](#api-str-replace)
    - [`whitelist($chars)`](#api-whitelist)
- Mixed
    - [`call($fn)`](#api-call)
    - [`map($map)`](#api-map)
    - [`set($items)`](#api-set)
- Locale rules
    - [`cnpj()`](#api-cnpj)
    - [`cpf()`](#api-cpf)
- Meta
    - [`dependsOn()`](#api-depends-on)
- Obligatoriness
    - [`optional()`](#api-optional)
    - [`required()`](#api-required)
    - [`skippable()`](#api-skippable)
- Numeric rules
    - [`range($min, $max)`](#api-range)

Methods
-------

[](#methods)

-  `any()`

    Validate all objects
-  `arrayOf($rule)`

    Validate every element on the array against the $rule
-  `blacklist($chars)`

    Remove any char found in $chars from the string
-  `boolval()`

    Convert the value to a boolean
-  `call($fn)`

    Call the function $fn to validate the value
-  `cnpj()`

    Brazilian CNPJ validator
-  `cpf()`

    Brazilian CPF validator
-  `date($format = null, $out = null)`

    Convert the value to a date using the format (or keep if alredy a \\DateTime)
-  `decimal($digits, $decimal, $decimalSeparator = null, $thousandsSeparator = null)`

    Convert the value to a decimal with $digits and $decimal (needs rtlopes\\Decimal)
-  `dependsOn()`

    Add a rule dependency. (Only works for objects)
-  `floatval($decimal = null, $thousands = null, $asString = false)`

    Convert the value to a float
-  `instanceOf($type)`

    Check if the object is an instance of the given type
-  `intval()`

    Convert the value to an int and fails if cannot be safely convertible
-  `len($min, $max = null)`

    Check for string or array length
-  `map($map)`

    Map a value to another
-  `minlen($min)`

    Check if string has at least $min length
-  `obj($definition)`

    Convert the value to an object and validate its fields
-  `optional()`

    Optional validator (Bypass if null or '')
-  `preg_replace($search, $replace)`

    Replace the $search pattern on the string using $replace (Callback or string)
-  `range($min, $max)`

    Range validator
-  `regex($pattern)`

    Validate the value against the $pattern
-  `required()`

    Required validator (Fails if null or '')
-  `set($items)`

    Check if value is in set
-  `skippable()`

    Skippable validator (Bypass if null or '' and does not set the property)
-  `str_replace($search, $replace)`

    Replace the characters on the string
-  `strval($trim = true)`

    Convert the object to a string value
-  `whitelist($chars)`

    Remove any char NOT found in $chars from the string

###  Health Score

38

↓

LowBetter than 85% of packages

Maintenance42

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 99.1% 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 ~125 days

Recently: every ~317 days

Total

15

Last Release

1347d ago

Major Versions

1.2.2 → v2.0.02018-10-07

### Community

Maintainers

![](https://www.gravatar.com/avatar/45d58ac83551eff8e1a531fb41c3b1fd57bb952986f46858e161f7352ef4482b?d=identicon)[renanhangai](/maintainers/renanhangai)

---

Top Contributors

[![rhangai](https://avatars.githubusercontent.com/u/1877289?v=4)](https://github.com/rhangai "rhangai (115 commits)")[![erickbonas](https://avatars.githubusercontent.com/u/1825196?v=4)](https://github.com/erickbonas "erickbonas (1 commits)")

---

Tags

phpvalidatorvalidatordataSimplevalidate

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/renanhangai-validator/health.svg)

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

###  Alternatives

[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)[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)[form-manager/form-manager

PHP-HTML form manager

16041.0k7](/packages/form-manager-form-manager)

PHPackages © 2026

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