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

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

mortimer333/validate
====================

Validates your data from predefined schema or by single method

1.0.0(5y ago)031GPL-2.0-onlyPHP

Since Mar 31Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Mortimer333/Validate)[ Packagist](https://packagist.org/packages/mortimer333/validate)[ RSS](/packages/mortimer333-validate/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (3)DependenciesVersions (2)Used By (0)

Validate
========

[](#validate)

Validates your data from predefined schema or by single method

```
  $spec = [
    "set" => [
      "user_id" => [ "int"          , "ID"    ],
      "login"   => [ "string"       , "Login" ],
      "name"    => [ "string_empty" , "Name"  ],
      "bio"     => [ ["!js","!php" ], "Bio"   ],
      "add"     => [ "array"        , "Additional", [
          "set" => [
            "created" => ["types" => "date"]
          ],
          "free" => ["string","int"]
        ]
      ]
    ]
  ];

  $data = [
    "user_id" => 0,
    "login"   => "login",
    "name"    => "name",
    "bio"     => "",
    "add"     => [
      "created" => "2020-01-01",
      "nana",
      "age" => 12
    ]
   ];

  if ( !Vali::dat( $data, $spec ) ) echo Vali::GetError();
```

Installation
============

[](#installation)

Installation method is via composer and its packagist package [validat/validat](https://packagist.org/packages/validat/validat "validat/validat").

```
  composer require validat/validat
```

How to use
==========

[](#how-to-use)

Method
------

[](#method)

All functions are static so you could call them anywhere, anytime. If you wanna check if your array is associative `Vali::Assoc( array( 'a' => 'b' ) )`, if you want to assign name to validation for clearer errors `Vali::Assoc( array( 'a' => 'b' ), 'My assoc array' )`, if you wanna check if it's not associative array `Vali::Assoc( array( 'a' => 'b' ), 'My assoc array', true )` or just `!Vali::Assoc( array( 'a' => 'b' ), 'My assoc array' )`. All function and their usage is explained below but you get the idea.

Schema
------

[](#schema)

Schema is predefined structure of data you want to validate. It helps if you recive multiple, nested variables in your API and don't wanna create hundreds of ifs to validate them.

Structure is divided into `set` and `free` variables. The `set` is validated first then all left values with `free`. You can assign them names (for geting clearer errors) and types. Available types :

- int
- decimal
- array
- bool (boolean)
- date
- string (will return false if string is empty)
- string\_empty (will return true if string is empty)
- object
- null
- js (will return true if string contains javascript)
- php (will return true if string contains php)
- mail
- json (checks if string is available to be read as JSON)

It's possible to check if data isn't something. Just add `!` before type and it will revert it. Example: `[..] 'desc' => ['name' => 'Description', 'types' => ['!js','!php']] [..]`. Now it will return false if `desc` contains any js or php.

If you don't want to use `string_empty` because all your strings can be empty just change the default setting `Vali::$_STRING_EMPTY` to true. It will change the behaviour of `String` function to return true even if string is empty.

And finaly errors: when error occurrs (when variable isn't valid or doesn't exist) apropriate error will be saved into `$_LAST_ERROR` as a string. To get error you can use `Vali::GetError()`.

Dynamic type assign
-------------------

[](#dynamic-type-assign)

What's cool is that you can change the validated type of variable by sending diffrent data and using keyword `this`. The script will look out in current scope for indicated data and use it contents as `types`. Example :

```
$spec = [
    "check" => [
      "set" => [
        "type" => [ "string"   , "Type of sent data" ],
        "data" => [ "this.type", "Data"              ]
      ]
    ]
  ];

  $data = [
    "type" => 'int',
    "data" => 'a',
  ];

  if ( !Vali::dat( $data, $spec ) ) echo Vali::GetError(); // output : Data is not a number.
```

FUNCTIONS
=========

[](#functions)

Legend:
-------

[](#legend)

- `$var` - variable to validate
- `$name` - the name to use in error
- `$reverse` - reverse the behaviour of method

Usage
-----

[](#usage)

- `Vali::Int($var, ?string $name = null, bool $reverse = false)`
- `Vali::String($var, bool $empty = false, ?string $name = null, bool $reverse = false)`
- `Vali::Decimal($var, ?string $name = null, bool $reverse = false)`
- `Vali::Day($var, ?string $name = null, bool $reverse = false)`
- `Vali::Bool($var, ?string $name = null, bool $reverse = false)`
- `Vali::Null($var, ?string $name = null, bool $reverse = false)`
- `Vali::Array($var, ?string $name = null, bool $empty = true, bool $reverse = false)`
- `Vali::Assoc($var, ?string $name = null, bool $empty = true, bool $reverse = false)`
- `Vali::Object($var, ?string $name = null, bool $reverse = false)`
- `Vali::JS($var, ?string $name = null, bool $reverse = false)`
- `Vali::PHP($var, ?string $name = null, bool $reverse = false)`
- `Vali::JSON($var, ?string $name = null, bool $reverse = false)`
- `Vali::Mail($var, ?string $name = null, bool $reverse = false)`

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

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

Unknown

Total

1

Last Release

1910d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c3dbf637bda39a5c8bd9102bf5a02d3333fc22d58c11348f0d4c66194e7d7f32?d=identicon)[Mortimer333](/maintainers/Mortimer333)

---

Top Contributors

[![Mortimer333](https://avatars.githubusercontent.com/u/34005580?v=4)](https://github.com/Mortimer333 "Mortimer333 (21 commits)")

---

Tags

validation

### Embed Badge

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

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

###  Alternatives

[composer/semver

Version comparison library that offers utilities, version constraint parsing and validation.

3.3k510.9M892](/packages/composer-semver)[giggsey/libphonenumber-for-php

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

5.0k156.0M487](/packages/giggsey-libphonenumber-for-php)[respect/validation

The most awesome validation engine ever created for PHP

6.0k39.0M407](/packages/respect-validation)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k38.3M138](/packages/propaganistas-laravel-phone)[opis/json-schema

Json Schema Validator for PHP

64941.2M259](/packages/opis-json-schema)[giggsey/libphonenumber-for-php-lite

A lite version of giggsey/libphonenumber-for-php, which is a PHP Port of Google's libphonenumber

9015.3M63](/packages/giggsey-libphonenumber-for-php-lite)

PHPackages © 2026

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