PHPackages                             johnbrightn/simple-field-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. johnbrightn/simple-field-validator

ActiveLibrary

johnbrightn/simple-field-validator
==================================

A simple yet powerful field backend input field validator for php

v1.4(5y ago)014Apache-2.0PHPPHP &gt;=5.3.0

Since Jan 24Pushed 5y ago2 watchersCompare

[ Source](https://github.com/johnbrightn/simple-field-validator)[ Packagist](https://packagist.org/packages/johnbrightn/simple-field-validator)[ Docs](https://github.com/johnbrightn/simple-field-validator)[ RSS](/packages/johnbrightn-simple-field-validator/feed)WikiDiscussions master Synced today

READMEChangelog (5)DependenciesVersions (6)Used By (0)

simple-field-validator
======================

[](#simple-field-validator)

#### Installing ? using composer

[](#installing--using-composer)

```
composer require johnbrightn/simple-field-validator

```

If you get an error of no class found, run the following command to optimize autoload

```
composer dump -o

```

#### Usage

[](#usage)

Mostly used with API where request objects are received as array.

```
    $userInputs = $request->getParsedBody(); //object received from user/frontend

 //specify required fields, key=>maxLength. value is the maximum required length of every field/key

    $requiredFields = ["first_name"=>25, "last_name"=>25, "email"=>60, "username"=>15, "password"=>20];

    $value = ValidateFields::validate($requiredFields, $userInputs); //method to validate fields
```

###### Method params descriptions

[](#method-params-descriptions)

```
ValidateFields::validate($requiredFields, $requestObject, $customMessage=null)
```

***parameter description***
`$requiredFields` array - specified fields that you're expecting from the user/front end
`$requestObj` array - array of fields of key/values from the user/front end
`$customMessage` optional parameter. array or custom messages to return when validation fails \\ \\

Example usage

```
require_once __FILE__ . '/vendor/autoload.php';

use Jbn\Validate\ValidateFields;

$app->post('/register', function (Request $request, Response $response) {

    $userInputs = $request->getParsedBody(); //object received from user/frontend

    //if there are optional fields, that do not need validation, do not specify them in the required fields array
   /* $middle_name = null;
    if(isset($request->getParsedBody()['middle_name']))
        $middle_name = $request->getParsedBody()['middle_name'];
   */
    //specified required fields, key=>maxLength. value is the maximum required length of every field/key
    $requiredFields = ["first_name"=>25, "last_name"=>25, "email"=>60, "username"=>15, "password"=>20];

    $value = ValidateFields::validate($requiredFields, $userInputs);
   if ($value["error"]) { //if validation fails, return response
        return $response->withJson($value);
    } else {
        //if validation succeeds, u can either use the returned values or the user input values which may include optional fields
        $value; // values retured from the array, which include required fields only
        $userInput //values sent by the user which may include optional fields

        ... do other works with the valid fields
        $result = $db->registerUser($value);

        return $response->withJson($result);
    }
});
```

If validation fails, array returned is

```
//if all required fields are not present
["error"=>true, "message"=> "No field is set"];

//if a required field is empty
["error"=>true, "message"=> "$field_name should not be empty"];

//if a required field has length more than specified
["error"=>true, "message"=> "$field_name should be $maxLength characters or less"];

//email validation. if email address is present, field should be specified as 'email',
["error"=>true, "message"=> "Invalid email address"];
```

If validation succeeds, returns all the fields together with their values

```
["error"=>false, $all_fields=>$all_values];
```

You can specify your custom messages when the value is empty or field length is more than the specified as a third parameter

```
    $userInputs = $request->getParsedBody();

    //specified required fields, key=>maxLength. value is the maximum required length of every field/key
    $requiredFields = ["first_name"=>25, "last_name"=>25, "username"=>15, "password"=>20];

    $customMessage = ["Oops! First Name should not be blank and not more than 25 characters", "Enter your last name and not more than 25 characters", "Enter a username of 15 characters or less", "Password should not exceed 20 characters"];

    $value = ValidateFields::validate($requiredFields, $userInputs, $customMessage);
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

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

Total

5

Last Release

2016d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8d328233de911adbd942741e30e79e46b52b1ca759cc4241ede346f34671789b?d=identicon)[johnbrightn](/maintainers/johnbrightn)

---

Top Contributors

[![johnbrightn](https://avatars.githubusercontent.com/u/31578504?v=4)](https://github.com/johnbrightn "johnbrightn (26 commits)")

### Embed Badge

![Health badge](/badges/johnbrightn-simple-field-validator/health.svg)

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

PHPackages © 2026

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