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

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

hypnokizer/validator
====================

Class to validate a dataset.

v7.0.0(1mo ago)04MITPHPPHP &gt;=8.3.0

Since Jun 4Pushed 1mo agoCompare

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

READMEChangelogDependencies (1)Versions (2)Used By (0)

Validator Class
===============

[](#validator-class)

This is a simple validator class. It can be used without dependancies, but extends the database class. It is based on `https://github.com/devwithkunal/php-validator-class`.

Basic Use
---------

[](#basic-use)

Create the class instance. The constructor parameter is an associative data array to be validated containing key value pairs of field names and values. If the `$data` is not specified, the class attempts to pull in POST data, then GET data.

```
$v = new Validator($data);

```

Run validation checks by chaining methods to the `field()` method. The `field()` method must start every method chain.

Check if the data is valid using the `isValid()` method.

```
if($v->isValid() == false) {
    print_r($v->errors);
}

```

Basic Methods
-------------

[](#basic-methods)

To start validation of a field, use the `field()` method. Once all validations are performed, use the `isValid()` method to determine if they were successful.

MethodDescription`field($name, $alias)`Set the field name to start validation.
`$name` - Name of the field/key to validate.
`$alias` - Alias to use in error messages instead of the field name.`isValid()`Check if all validations are successful.Validation methods available
----------------------------

[](#validation-methods-available)

After the `field()` method is called for a field, you can chain validation methods for each field.

MethodDescription`alpha($ignore)`Check for alphabetic characters.`alphanumeric($ignore)`Check for alphanumeric characters.`changecase($case)`Change case of string: capitalize, uppercase, lowercase.`contains($chars)`Check if the value contains specific characters.`date()`Check for a valid date.`dateafter($date)`Check if a date comes after the given date.`datebefore($date)`Check if a date comes before the given date.`email()`Check for email address.`enum($list)`Check if a value is in the list of approved values.`equals($value)`Check if value is equal to a given value.`integer()`Check for integer.`length($length)`Check for exact length of string.`maxlength($length)`Check for maximum length of string.`maxvalue($value)`Check for maximum value of integer or float.`minlength($length)`Check for minimum length of string.`minvalue($value)`Check for minimum value of integer or float.`money($ignore)`Check for currency. Changes string to decimal by removing dollar signs, commas, decimals, and negative signs.`numeric()`Check for numeric characters.`period()`Check for a date string and convert it to a period (Ex: Y-m-01).`phone()`Check for valid U.S. phone number. Removes non-numeric characters and confirms length of string.`regex($pattern)`Check against a regex pattern.`required()`Check if the required value exists.`state()`Check for valid U.S. state abbreviation.`zip()`Check for valid U.S. zip code.Example
-------

[](#example)

```
require('Validator.php');

use Hypnokizer\Validator;

// test data to validate
$data = array(
    'fname' => 'nathan randall',
    'lname' => 'Kizer',
    'username' => 'hypnokizer1729!',
    'emailaddy' => 'nathan.kizer@test.com',
    'password' => 'P@ssword!!',
    'password-confirm' => 'mypassword2',
    'age' => 50,
    'sex' => 'male',
    'state' => 'WY',
    'zip' => '79407-3711',
    'phone' => '806-441-8282',
    'dob' => '01/02/1976',
    'month' => 'Jan2026',
    'payment' => '-$4,226.95'
);

$v = new Validator($data);

$v->field('fname')->required()->changecase('capitalize');
$v->field('lname', 'Last name')->required()->length(4);
$v->field('username')->required()->regex('/^[A-Za-z0-9]+$/');
$v->field('emailaddy')->required()->email();
$v->field('age')->minvalue(45)->maxvalue(55)->integer();
$v->field('sex')->enum(['male', 'female']);
$v->field('state')->required()->state();
$v->field('zip')->required()->zip();
$v->field('phone')->required()->phone();
$v->field('password')->minlength(10)->maxlength(15)->contains('a-z')->contains('@')->contains('A-Z');
$v->field('password-confirm')->required()->equals($data['password']);
$v->field('dob')->required()->date()->dateafter('January 2, 1976')->datebefore('January 3, 1976');
$v->field('month')->required()->period();
$v->field('payment')->required()->money();

// custom error; validation takes place in if() statement
if(1 == 2) {
    $v->field('mycustom')->customError('{field} is incorrect');
}

if($v->isValid() == false) {
    echo 'ERRORS FOUND:';
    print_r($v->errors);
    echo '';
}

```

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance90

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

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

50d ago

### Community

Maintainers

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

---

Top Contributors

[![Hypnokizer](https://avatars.githubusercontent.com/u/279126957?v=4)](https://github.com/Hypnokizer "Hypnokizer (15 commits)")

### Embed Badge

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

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

###  Alternatives

[hybridlogic/validation

A simple, extensible validation library for PHP with support for filtering and validating any input array along with generating client side validation code.

641.1k](/packages/hybridlogic-validation)

PHPackages © 2026

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