PHPackages                             juanchosl/validators - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. juanchosl/validators

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

juanchosl/validators
====================

Little methods collection in order to validate variables contents

1.0.9(3w ago)13874MITPHPPHP ^8.1

Since Mar 4Pushed 4d ago1 watchersCompare

[ Source](https://github.com/JuanchoSL/Validators)[ Packagist](https://packagist.org/packages/juanchosl/validators)[ Docs](https://github.com/JuanchoSL/Validators)[ RSS](/packages/juanchosl-validators/feed)WikiDiscussions 1.0 Synced 1w ago

READMEChangelog (10)Dependencies (7)Versions (12)Used By (4)

Validators
==========

[](#validators)

Description
-----------

[](#description)

Little methods collection in order to validate variables contents

Install
-------

[](#install)

```
composer require juanchosl/validators
composer update
```

How to use
----------

[](#how-to-use)

### Validation availability

[](#validation-availability)

- Strings
- Hashes (with and without HMAC)
- General numbers
- Specific integers
- Specific floats
- Iterables (all types)
- Array (in Specific, indexed or associative)
- List (indexed array with keys from 0 to count()-1)
- Collection (iterable of iterables)
- Entity (iterable with named keys, as objects or assoc arrays)
- Primitive boolean, reals or equivalents and Null checking

> Important: from version 1.0.9 the multi-validations classes has been callables, you can prepare a sequence of validations into a variable and call it as a unction with the values to check as parameters.
>
> The **getResult** method, maybe can be removed on future versions

#### How works

[](#how-works)

##### Primitives and scalars

[](#primitives-and-scalars)

The validators checking the type of value, and provide a relative options, as a number compartions for NumberValidators, but not for StringValidators, or a PrimitiveValidation::isBoolEquivalent for strings as true, yes, on, false, no, off...but not on StringValidation (a string false is a string really), in order to reduce and group the logics for every task

##### Hashes

[](#hashes)

We have the hash and hashhmac signatures validations, usefull for any project, can be reused very easy in any task, as to verificate downloaded or received files, authorization headers, security tokens, payloads, etc...

##### Iterables

[](#iterables)

We have some grouped validations for each type of structures, can be checked distincts type of iterables for any situation

- **List** is an indexed array with numbered keys from 0 to count($) - 1, true for indexed array, false for associative
- **Array** indexed with any key order, or assoc with text keys
- **Iterable** parent of List and Array
- **Entity** any iterable with named keys, array or objects are valid
- **Collection** an iterable of iterables, calling validations from here, launch the validation for every contained *Entity*

The iterables have validations with the same name of scalar validations (isValueContaining, isValueValidating...), but perform the checking over each element, in order to verify all contents with an only call. As Scalar validations, not all iterables have the same validators, a list does not check keys, because needs to be auto-numbered, List and Array, does not have validation over child attributes, its are used for a gruped of scalar values.

> Iterable mantains the availability for retro compatibility, but maybe it will be removed in the future, relegatting this responsability to Collection and Entity

#### Generic methods

[](#generic-methods)

ValidationStringsNumbersIterablesPrimitivesHashesisxxxxxisEmptyxxxxxisNotEmptyxxxxxisValueStartingWithxxisValueStartingWithAnyxxisValueEndingWithxxisValueEndingWithAnyxxisValueContainingxxxisValueContainingAnyxxxisValueValidatingxxxisValueValidatingAnyxxxisValueEqualsxxisValueEqualsAnyxxisLengthEqualsThanxxxisLengthGreatherThanxxxisLengthGreatherOrEqualsThanxxxisLengthLessThanxxxisLengthLessOrEqualsThanxxxisRegexxx#### Exclusive methods

[](#exclusive-methods)

StringsPrimitivesNumericsHashesIterablesisNumberisBoolEquivalentisValueEqualsThanisValidatingHashisValueAttributeValidatingisIntegerisNullisValueEqualsThanAnyisValidatingHashHmacisValueAttributeValidatingAnyisFloatisTrueisValueIntoRangeisHashisAnyValueAttributeValidatingisBinaryisFalseisValueGreatherThanisAnyValueAttributeValidatingAnyisHexadecimalisValueGreatherThanOrEqualsisAnyValueValidatingisMultibyteisValueLessThanisAnyValueValidatingAnyisEncodedAsisValueLessThanOrEqualsisKeyContainingisEmailisKeyContainingAnyisUrlisIpV4isIpv6isMacisDomainisDateisSerialized### Single validation

[](#single-validation)

You can perform an only check over a single value

```
StringValidation::isEmail("juanchosl@hotmail.com"); //true
```

### Multiple validations over 1 value

[](#multiple-validations-over-1-value)

You can perform a few checks over a single value

```
$validator = new StringValidations();
$validator
    ->is()
    ->isNotEmpty()
    ->isLengthGreatherThan(15)
    ->isEmail();

$validator('juanchosl@hotmail.com'); //true

print_r($validator->getResults('juanchosl@hotmail.com'));
Array
(
    [is] => 1
    [isNotEmpty] => 1
    [isLengthGreatherThan: 15] => 1
    [isEmail] => 1
)
```

### Multiple validations over multiple values

[](#multiple-validations-over-multiple-values)

You can perform a few checks over multiple values

```
$validator = new StringValidations();
$validator
    ->is()
    ->isNotEmpty()
    ->isLengthGreatherThan(15)
    ->isEmail();

    foreach(['juanchosl@hotmail.com', 'email@corporation.com'] as $text){
        $validator($text); //true

        print_r($validator->getResults($text));
        Array
        (
            [is] => 1
            [isNotEmpty] => 1
            [isLengthGreatherThan: 15] => 1
            [isEmail] => 1
        )
    }
```

### Alternative validations (OR) over values

[](#alternative-validations-or-over-values)

You can perform some alternative checks over the values in order to accept it if pass ANY of some condicions

```
$validator = new StringValidations();
$validator
    ->is()
    ->isNotEmpty()
    ->isValueEqualsAny('juan','pepe','antonio');

$validator('juan'); //true
```

### Validations over associative arrays or entities

[](#validations-over-associative-arrays-or-entities)

You can perform checks over the values of an associative array or object, can be simple validations or any other complex validation, indicating the target index. The results of the validations are unitary, for each element

```
$datas = [
    ["nombre" => "pepe", "apellidos" => "salmuera", "email" => "aaaa@bbb.com", "telephone" => 123456789],
    ["nombre" => "juan", "apellidos" => "benito", "email" => "bbb@ccc.es", "telephone" => 123456789],
];

// Option 1
$validator = new EntityValidations();
$validator->isValueAttributeValidating('email', (new StringValidations())->isEmail());
$validator->isValueAttributeValidating('telephone', (new IntegerValidations())->isLengthGreatherOrEqualsThan(9)->isLengthLessOrEqualsThan(12));

foreach($datas as $data){
    $result = $validator($data);// We have the unitary result or each element
    if($result === true){
        ...//our code execution
    }
}

//Option 2
$validator = new CollectionValidations();
$validator->isValueAttributeValidating('email', (new StringValidations())->isEmail());
$validator->isValueAttributeValidating('telephone', (new IntegerValidations())->isLengthGreatherOrEqualsThan(9)->isLengthLessOrEqualsThan(12));

$validator($datas);//We have the global result, for all elements
```

### Validations over iterables

[](#validations-over-iterables)

Instead of iterate over a collection, as the previous example, you can perform checks over the keys or values of an iterable, can be simple validations or any other complex validation

```
$validator = new IterableValidations();
$validator
    ->is()
    ->isNotEmpty()
    ->isKeyContainingAny(...['nombre', 'apellidos']);

$validator(['nombre' => 'Cadena numeros', 'apellidos' => 'Cadena letras']);//true

******

$datas = [
    ["nombre" => "pepe", "apellidos" => "salmuera", "email" => "aaaa@bbb.com", "telephone" => 123456789],
    ["nombre" => "juan", "apellidos" => "benito", "email" => "bbb@ccc.es", "telephone" => 123456789],
];
$validator->isValueAttributeValidating('email', (new StringValidations())->isEmail());
$validator->isValueAttributeValidating('telephone', (new IntegerValidations())->isLengthGreatherOrEqualsThan(9)->isLengthLessOrEqualsThan(12));

$validator($datas);//false
/*
Array
(
    [isValueAttributeValidating: email,StringValidations->isEmail] => 1
    [isValueAttributeValidating: telephone,IntegerValidations->isLengthGreatherOrEqualsThan(9)->isLengthLessOrEqualsThan(12)] => 1
)
*/
```

```
$datas = ["aaaa@bbb.com", "bbb@ccc.es"];
$validator = new IterableValidations();
$validator->isValueValidating((new StringValidations())->isEmail());
$validator($datas);
```

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance97

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity58

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

Recently: every ~66 days

Total

11

Last Release

19d ago

PHP version history (3 changes)1.0.0PHP ^7.1 || ^8.0

1.0.6PHP ^8.0

1.0.8PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18701207?v=4)[Juan Sánchez](/maintainers/Juanchosl)[@JuanchoSL](https://github.com/JuanchoSL)

---

Top Contributors

[![JuanchoSL](https://avatars.githubusercontent.com/u/18701207?v=4)](https://github.com/JuanchoSL "JuanchoSL (95 commits)")

---

Tags

logvalidatorvalidationstringdebugvalidatenumbersiterables

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/juanchosl-validators/health.svg)

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

###  Alternatives

[sentry/sentry

PHP SDK for Sentry (http://sentry.io)

1.9k254.3M366](/packages/sentry-sentry)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k39.6k](/packages/matomo-matomo)[illuminate/log

The Illuminate Log package.

6225.7M690](/packages/illuminate-log)[analog/analog

Fast, flexible, easy PSR-3-compatible PHP logging package with dozens of handlers.

3441.6M24](/packages/analog-analog)[inpsyde/wonolog

Monolog-based logging package for WordPress.

184643.6k7](/packages/inpsyde-wonolog)[pagemachine/typo3-formlog

Form log for TYPO3

23243.0k8](/packages/pagemachine-typo3-formlog)

PHPackages © 2026

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