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

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

cloudonaut/validator
====================

A simple reusable validator class

v1.0.1(5y ago)37MITPHP

Since Aug 24Pushed 5y ago1 watchersCompare

[ Source](https://github.com/bildekrokodil/Lib-Validator)[ Packagist](https://packagist.org/packages/cloudonaut/validator)[ RSS](/packages/cloudonaut-validator/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (3)Used By (0)

Cloudonaut Validator
====================

[](#cloudonaut-validator)

This is a simple reusable validator class for PHP.

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

[](#installation)

### Install with composer

[](#install-with-composer)

```
composer require cloudonaut/validator

```

Include it into your scripts by using composer autoload and create a new validator object.

```
require './vendor/autoload.php';
use Cloudonaut\Lib\Validator;
$validator = new Validator();
```

### Manueal installation

[](#manueal-installation)

Just copy the Validator.php file from the src folder to your project and include it into your scripts. Than create a new validator object.

```
require_once './PATH/TO/Validator.php';
use Cloudonaut\Lib\Validator;
$validator = new Validator();
```

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

[](#basic-usage)

The validator stores violations automatically when there is a violation against a rule. To check is a validator has violations you can use the hasViolations() function. To get an array of the violations you can call getViolations(). To add violations you can use one of the many build in check functions or simply add a violation to the list using your own code to check the value.

### Example using a build in check isNotEmpty

[](#example-using-a-build-in-check-isnotempty)

Check if a value is not empty. If it is empty a violation is added to the validator object.

```
$value = "";
$msg = "Value can't be empty";
$validator->isNotEmpty($value, $msg);
if ($validator->hasViolations())
{
    implode("," $validator->getViolations());
}
```

Output

```
Value can't be empty

```

### Example using addViolation

[](#example-using-addviolation)

In this example we need the value to match 7 as a simple example. But you can build on this example to do other stuff with value. For example: Call another api and based on the result validate the value, check the value against a database table etc...

```
$value = 8;
$msg = "Value must be 7";
if ($value != 7)
{
    $validator->addViolation($msg);
}

if ($validator->hasViolations())
{
    implode("," $validator->getViolations());
}
```

output

```
Value must be 7

```

### Example combining rules

[](#example-combining-rules)

You can check the same or other values as many as you want. For example. A e-mail adres must be filled in and a name. But a name is text only.

```
$name = "R2D2"; // wrong name
$mail="test.example.com"; //wrong mail

$validator->isNotEmpty($name, "Name can't be empty");
$validator->isNotEmpty($mail, "Mail can't be empty");
$validator->isTextOnly($name, "Name can't have numbers");
$validator->isEmail($name, "Mails is not in the correct format");

if ($validator->hasViolations())
{
    implode(", " $validator->getViolations());
}
```

output

```
Name can't have numbers, Mails is not in the correct format

```

Basic functions
---------------

[](#basic-functions)

### addViolation($msg='')

[](#addviolationmsg)

Adds a violation with the given message

### hasViolations()

[](#hasviolations)

Checks if the validator has violations. It will return true when there are violations or false when there are no violations.

### getViolations()

[](#getviolations)

Returns an array of the messages of all the violations. If there are no violations it just returns an empty array.

Build in checks
---------------

[](#build-in-checks)

All functions will also return true when no violation is added and false when the value violates the rule.

### isNotEmpty($value, $msg='')

[](#isnotemptyvalue-msg)

Adds a violation when the value is empty.

### isText($value,$msg='')

[](#istextvaluemsg)

Adds a violation when the value is not alphanumeric

### isTextOnly($value,$msg='')

[](#istextonlyvaluemsg)

Adds a violation when the value is not containing only letters.

### isNumber($value,$msg='')

[](#isnumbervaluemsg)

Adds a violation when the value is not a number.

### isDigit($value,$msg='')

[](#isdigitvaluemsg)

Adds a violation when the value contains anything else than number characters.

### isBetween($min, $max, $value, $msg='')

[](#isbetweenmin-max-value-msg)

Adds a violation when the value is not between the min and max value.

### isComplex($value,$msg='')

[](#iscomplexvaluemsg)

Adds a violation when the value is not containing:

- At least one lower case letter
- At least one upper case letter
- At least one number or symbol
- and should be between 8 and 20 characters long

### isDate($value,$msg='')

[](#isdatevaluemsg)

Adds a violation when the value is not a date in the folowing format: yyyy-mm-dd

### isTime($value,$msg='')

[](#istimevaluemsg)

Adds a violation when the value is not a time indication in the folowing format: hh:mm:ss

### isEmail($value,$msg='')

[](#isemailvaluemsg)

Adds a violation when the value is not an e-mail address

### isURL($value,$msg='')

[](#isurlvaluemsg)

Adds a violation when the value is not an URL.

### isIP($value,$msg='')

[](#isipvaluemsg)

Adds a violation when the value is not an IP address. (v4)

### isFilename($value,$msg='')

[](#isfilenamevaluemsg)

Adds a violation when the value is not a filename.

### isInList($value,$list, $msg='')

[](#isinlistvaluelist-msg)

Adds a violation when the value is not a given list.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

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

Total

2

Last Release

2093d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/511c8a92a77bab1716f42fc076867248687d51939a21e48e53b304172120ae23?d=identicon)[cloudonaut](/maintainers/cloudonaut)

### Embed Badge

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

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

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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