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

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

codesvault/validator
====================

Data validation library

1.2.2(2mo ago)31181[1 issues](https://github.com/CodesVault/validator/issues)MITPHPPHP &gt;=7.4

Since Jun 4Pushed 2mo agoCompare

[ Source](https://github.com/CodesVault/validator)[ Packagist](https://packagist.org/packages/codesvault/validator)[ RSS](/packages/codesvault-validator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (9)Used By (0)

Validator
=========

[](#validator)

Data validation composer package.

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

[](#installation)

Install using composer.

```
composer require codesvault/validator

```

Usage
-----

[](#usage)

```
$validator = Validator::validate(
    [
		'username'	=> 'required|stringOnly',
		'full_name'	=> 'stringWithSpace',
		'password'	=> 'required|min:8',
		'email'		=> 'required|email',
    ],
);

$data = $validator->getData();
```

It'll get data from `$_REQUEST` by default. But you also can pass data as second parameter.

```
$validator = Validator::validate(
	[
		'username'	=> 'required|stringOnly',
		'full_name'	=> 'stringWithSpace'
	],
	[
		'username'	=> 'abmsourav',
		'full_name'	=> 'Keramot UL Islam'
	]
);
```

Available Rules
---------------

[](#available-rules)

RuleDescriptionrequiredCheck the value is present in the input data and is not empty.emailCheck the value is valid email address.urlCheck the value is valid url.stringCheck the value is string.stringOnlyCheck the value is only string charecters.stringWithSpaceCheck the value is string with space.stringWithNumberCheck the value is string with number.stringWithDashCheck the value is string with dash and underscore.uppercaseCheck the value is string with upper case.lowercaseCheck the value is string with lower case.mixedCaseCheck the value is string with upper and lower case.stringWithSymbolsCheck the value is string with symbols.minCheck the value is greater than or equal to the given value.maxCheck the value is less than or equal to the given value.integerCheck the value is integer.sameValueCheck the value is same as the given value.arrayCheck the value is an array.eachvalidate each item of an array.boolvalidate boolean data

Examples
--------

[](#examples)

### Basic Validation Rules

[](#basic-validation-rules)

#### Required Rule

[](#required-rule)

Ensures the field is present and not empty.

```
$validator = Validator::validate(
    ['username' => 'required'],
    ['username' => 'john_doe']  // ✅ Valid
);

// Invalid examples:
// ['username' => '']         // ❌ Empty string
// ['username' => null]       // ❌ Null value
// []                         // ❌ Missing field
```

#### Email Rule

[](#email-rule)

Validates email address format.

```
$validator = Validator::validate(
    ['email' => 'email'],
    ['email' => 'user@example.com']  // ✅ Valid
);

// Invalid examples:
// ['email' => 'invalid-email']     // ❌ Invalid format
// ['email' => '@example.com']      // ❌ Missing username
// ['email' => 'user@']             // ❌ Missing domain
```

#### URL Rule

[](#url-rule)

Validates URL format.

```
$validator = Validator::validate(
    ['website' => 'url'],
    ['website' => 'https://example.com']  // ✅ Valid
);

// Also valid:
// ['website' => 'http://example.com']
// ['website' => 'ftp://files.example.com']

// Invalid examples:
// ['website' => 'not-a-url']       // ❌ Invalid format
// ['website' => 'example.com']     // ❌ Missing protocol
```

### String Validation Rules

[](#string-validation-rules)

#### String Only (stringOnly)

[](#string-only-stringonly)

Validates that the value contains only alphabetic characters.

```
$validator = Validator::validate(
    ['name' => 'stringOnly'],
    ['name' => 'John']  // ✅ Valid
);

// Invalid examples:
// ['name' => 'John123']            // ❌ Contains numbers
// ['name' => 'John Doe']           // ❌ Contains space
// ['name' => 'John-Doe']           // ❌ Contains dash
```

#### String with Spaces (stringWithSpace)

[](#string-with-spaces-stringwithspace)

Validates strings that can contain alphabetic characters and spaces.

```
$validator = Validator::validate(
    ['full_name' => 'stringWithSpace'],
    ['full_name' => 'John Doe']  // ✅ Valid
);

// Also valid:
// ['full_name' => 'Mary Jane Watson']

// Invalid examples:
// ['full_name' => 'John123']       // ❌ Contains numbers
// ['full_name' => 'John-Doe']      // ❌ Contains dash
```

#### String with Numbers (stringWithNumber)

[](#string-with-numbers-stringwithnumber)

Validates strings that can contain alphabetic characters and numbers.

```
$validator = Validator::validate(
    ['username' => 'stringWithNumber'],
    ['username' => 'user123']  // ✅ Valid
);

// Also valid:
// ['username' => 'JohnDoe456']

// Invalid examples:
// ['username' => 'user 123']       // ❌ Contains space
// ['username' => 'user-123']       // ❌ Contains dash
```

#### String with Dash (stringWithDash)

[](#string-with-dash-stringwithdash)

Validates strings that can contain alphabetic characters, dashes, and underscores.

```
$validator = Validator::validate(
    ['slug' => 'stringWithDash'],
    ['slug' => 'hello-world_page']  // ✅ Valid
);

// Also valid:
// ['slug' => 'my_awesome_post']
// ['slug' => 'hello-world']

// Invalid examples:
// ['slug' => 'hello world']        // ❌ Contains space
// ['slug' => 'hello123']           // ❌ Contains numbers
```

#### Case Validation Rules

[](#case-validation-rules)

```
// Uppercase only
$validator = Validator::validate(
    ['code' => 'uppercase'],
    ['code' => 'HELLO']  // ✅ Valid
);

// Lowercase only
$validator = Validator::validate(
    ['tag' => 'lowercase'],
    ['tag' => 'hello']  // ✅ Valid
);

// Mixed case (both upper and lower case required)
$validator = Validator::validate(
    ['password' => 'mixedCase'],
    ['password' => 'HelloWorld']  // ✅ Valid
);
```

#### String with Symbols (stringWithSymbols)

[](#string-with-symbols-stringwithsymbols)

Validates strings that can contain symbols and special characters.

```
$validator = Validator::validate(
    ['password' => 'stringWithSymbols'],
    ['password' => 'Pass@123!']  // ✅ Valid
);

// Also valid:
// ['password' => 'My$ecur3#Pass']
```

### Length Validation Rules

[](#length-validation-rules)

#### Minimum Length (min)

[](#minimum-length-min)

Validates minimum length/size requirements.

```
// String minimum length
$validator = Validator::validate(
    ['password' => 'min:8'],
    ['password' => 'mypassword']  // ✅ Valid (10 characters)
);

// Number minimum value
$validator = Validator::validate(
    ['age' => 'min:18'],
    ['age' => 25]  // ✅ Valid
);

// Array minimum items
$validator = Validator::validate(
    ['tags' => 'min:2'],
    ['tags' => ['php', 'javascript', 'html']]  // ✅ Valid (3 items)
);
```

#### Maximum Length (max)

[](#maximum-length-max)

Validates maximum length/size requirements.

```
// String maximum length
$validator = Validator::validate(
    ['title' => 'max:100'],
    ['title' => 'Short Title']  // ✅ Valid
);

// Number maximum value
$validator = Validator::validate(
    ['score' => 'max:100'],
    ['score' => 85]  // ✅ Valid
);

// Array maximum items
$validator = Validator::validate(
    ['categories' => 'max:5'],
    ['categories' => ['tech', 'news']]  // ✅ Valid (2 items)
);
```

### Data Type Rules

[](#data-type-rules)

#### Integer Rule

[](#integer-rule)

Validates that the value is an integer.

```
$validator = Validator::validate(
    ['age' => 'integer'],
    ['age' => 25]  // ✅ Valid
);

// Also valid:
// ['age' => '30']              // ✅ String numbers are valid

// Invalid examples:
// ['age' => 25.5]              // ❌ Float value
// ['age' => 'twenty']          // ❌ Text value
```

#### Array Rule

[](#array-rule)

Validates that the value is an array.

```
$validator = Validator::validate(
    ['tags' => 'array'],
    ['tags' => ['php', 'javascript']]  // ✅ Valid
);

// Invalid examples:
// ['tags' => 'php,javascript']     // ❌ String value
// ['tags' => 123]                  // ❌ Number value
```

### Advanced Rules

[](#advanced-rules)

#### Same Value (sameValue)

[](#same-value-samevalue)

Validates that the field value matches a specific value.

```
$validator = Validator::validate(
    ['confirmation' => 'sameValue:yes'],
    ['confirmation' => 'yes']  // ✅ Valid
);

// For password confirmation:
$validator = Validator::validate(
    [
        'password' => 'required|min:8',
        'password_confirmation' => 'sameValue:' . $_POST['password']
    ],
    $_POST
);
```

#### Each Rule

[](#each-rule)

Validates each item in an array against specified rules.

```
// Validate each email in an array
$validator = Validator::validate(
    ['emails' => 'each:email'],
    ['emails' => ['user1@example.com', 'user2@example.com']]  // ✅ Valid
);

// Validate each item with multiple rules (`&` [AND] operator)
$validator = Validator::validate(
    ['usernames' => 'each:required&stringOnly&min:3'],
    ['usernames' => ['john', 'jane', 'mike']]  // ✅ Valid
);

// Validate each item with OR operator
$validator = Validator::validate(
    ['identifiers' => 'each:email,integer'],
    ['identifiers' => ['user@example.com', 12345]]  // ✅ Valid
);
```

Form validation with Combining Multiple Rules
---------------------------------------------

[](#form-validation-with-combining-multiple-rules)

You can combine multiple rules using the pipe (`|`) separator:

```
$validator = Validator::validate(
    [
        'username'	=> 'required|stringOnly|min:3|max:20',
        'email'		=> 'required|email',
        'password'	=> 'required|min:8|mixedCase',
        'age'		=> 'required|integer|min:18|max:100',
        'tags'		=> 'array|min:1|max:10',
        'skills'	=> 'each:stringOnly&min:2'
    ],
    [
        'username'	=> 'johndoe',
        'email'		=> 'john@example.com',
        'password'	=> 'MySecure123',
        'age'		=> 25,
        'tags'		=> ['php', 'javascript'],
        'skills'	=> ['programming', 'design']
    ]
);

$data = $validator->getData();
```

### Error Handling Example

[](#error-handling-example)

If any data is invalid then `error` method will return error messages array. Otherwise it'll return empty array.

```
$validator = Validator::validate(
    [
        'username' => 'required|stringOnly|min:3',
        'email' => 'required|email'
    ],
    [
        'username' => 'ab',  // Too short
        'email' => 'invalid-email'  // Invalid format
    ]
);

$errors = $validator->error();
if ($errors) {
    // Handle validation errors
    foreach ($errors as $field => $message) {
        echo "Error in {$field}: {$message[0]}\n";
    }
}

$data = $validator->getData();
```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance77

Regular maintenance activity

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

Recently: every ~240 days

Total

8

Last Release

83d ago

PHP version history (2 changes)1.0.0PHP &gt;=7.1

1.2.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/8078871c211cddf84f3fcff8321f973ed3324aa0c54d0d8a2b5c3ad9ffa2fca2?d=identicon)[abmSourav](/maintainers/abmSourav)

---

Top Contributors

[![AbmSourav](https://avatars.githubusercontent.com/u/39233955?v=4)](https://github.com/AbmSourav "AbmSourav (48 commits)")

---

Tags

data-validationdata-validatorphpvalidationvalidation-libraryvalidatorvalidatorvalidationphp-validationdata validationphp-validatordata validatorcodesvalut

###  Code Quality

TestsPest

### Embed Badge

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

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

###  Alternatives

[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-validation)[opis/json-schema

Json Schema Validator for PHP

64736.9M186](/packages/opis-json-schema)[vlucas/valitron

Simple, elegant, stand-alone validation library with NO dependencies

1.6k4.4M128](/packages/vlucas-valitron)[intervention/validation

Additional validation rules for the Laravel framework

6826.7M8](/packages/intervention-validation)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[wixel/gump

A fast, extensible &amp; stand-alone PHP input validation class that allows you to validate any data.

1.2k1.3M30](/packages/wixel-gump)

PHPackages © 2026

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