PHPackages                             gavinggordon/input-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. [Testing &amp; Quality](/categories/testing)
4. /
5. gavinggordon/input-validator

ActiveLibrary[Testing &amp; Quality](/categories/testing)

gavinggordon/input-validator
============================

A PHP class which provides the ability to quickly validate user input, depending on a set of user-defined rules.

1.0.0(9y ago)119MITPHP

Since May 19Pushed 9y ago1 watchersCompare

[ Source](https://github.com/gavinggordon/input-validator)[ Packagist](https://packagist.org/packages/gavinggordon/input-validator)[ Docs](http://input-validator.gavingordon.com)[ RSS](/packages/gavinggordon-input-validator/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

InputValidator v1.0.0
=====================

[](#inputvalidator-v100)

[![Build Status](https://camo.githubusercontent.com/0b2f429aa6986426dd99e3fdf1c58e2d9b1d7a0e200a9353befc1385a448eb26/68747470733a2f2f7472617669732d63692e6f72672f676176696e67676f72646f6e2f696e7075742d76616c696461746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/gavinggordon/input-validator)

---

Prologue
--------

[](#prologue)

Quickly define and run validation check on user data provided upon either GET or POST requests.

---

### Installation (via Composer)

[](#installation-via-composer)

```
composer require gavinggordon/input-validator

```

### Include autoloader.php

[](#include-autoloaderphp)

```
include_once( __DIR__ . '/vendor/autoload.php' );

```

### Examples

[](#examples)

#### Set Rules

[](#set-rules)

The rules array contains the validation rules for each input. Each input is equal to 1 array, and, in itself, contains the rules for its own validation.

The first parameter of an input's validation array is used to define the Regex pattern by which to validate its value against.

The second parameter, which is also an array, is used to define the string length of the value, noted by the first parameter as a minimum length, followed by a maximum length.

```
$rules = [
  [
    'alpha', [ 5,16 ]
  ],
  [
    'phone', [ 7,15 ]
  ],
  [
    'alpha_number_symbol_spaces', [ 2,155 ]
  ]
];

```

#### Create Instance

[](#create-instance)

To instantiate the class, two arguments are required:

The first argument must be a string value of either 'GET' or 'POST', and is used to determine the request type being validated.

The second argument must be an array of rules, as mentioned in the above example.

```
$validator = new GGG\InputValidator( 'POST', $rules );

```

#### Run the Validator

[](#run-the-validator)

```
$validated = $validator->validate();

```

#### Determine if Validated

[](#determine-if-validated)

```
// if passed validation
if( $validated === true ) {

  // retrieve an associative array of inputs
  $data = $validator->getInputs();

}

// if has errors
if( is_array( $validated ) ) {

  // show an array containing messages for
  // each input which did not pass validation.
  var_dump( $validated );

}

```

---

#### More Information

[](#more-information)

##### Feedback

[](#feedback)

If you found this class to be at all interesting, helpful, particularly useful, or innovative in any way, check out my other PHP classes via my [GitHub profile](https://github.com/gavinggordon) or [PHPClasses.org profile](http://www.phpclasses.org/browse/author/1348645.html).

---

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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

3647d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0265c11e917254193d286a481b3fa7794c4dd83ba29f71d239a19c1724956566?d=identicon)[gavinggordon](/maintainers/gavinggordon)

---

Top Contributors

[![gavinggordon](https://avatars.githubusercontent.com/u/7691513?v=4)](https://github.com/gavinggordon "gavinggordon (5 commits)")

---

Tags

phptestcheckvalidatorvalidationsecurityprocessingdatavalidateforminputsafetyv1.0.0preprocessing

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[nilportugues/assert

A simple and elegant assertion and guard methods library for input validation.

1066.0k7](/packages/nilportugues-assert)[progsmile/request-validator

Simple PHP Request Validator

33113.3k1](/packages/progsmile-request-validator)[nilportugues/validator

An efficient data validator for PHP

131.5k](/packages/nilportugues-validator)

PHPackages © 2026

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