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

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

ongom/php-validator
===================

A PHP library for validating input

v1.0.0(1y ago)01MITPHP

Since May 18Pushed 1y ago1 watchersCompare

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

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

📄 PHPValidator
==============

[](#-phpvalidator)

A flexible PHP validation class for validating strings, numbers, and files. It supports both static chaining and method chaining for clear and readable validation rules.

### ✅ Available Static Methods

[](#-available-static-methods)

the name spce id `use PHPValidator\Validate``Validate::string($value, $fieldName)` -Initialize validation for a string.

`Validate::number($value, $fieldName)` -Initialize validation for a number (int or float).

`Validate::file($key, $source = null, $fieldName = 'File')`-Initialize validation for an uploaded file. `$key` is the name of the `$_FILES array`. `$source` can be `FILES` or a custom file array (e.g. from an API).

### 🔤 String Validation Methods

[](#-string-validation-methods)

`Validate::string($value, $fieldName)`

MethodDescription`->min_length($len)`Requires a minimum number of characters.`->max_length($len)`Requires a maximum number of characters.`->uppercase()`Requires at least one uppercase character.`->lowercase()`Requires at least one lowercase character.`->has_number()`Requires at least one numeric digit.`->special_character()`Requires at least one special character (non-alphanumeric).`->email()`Checks if the string is a valid email address.`->url()`Checks if the string is a valid URL.### 🔢 Number Validation Methods

[](#-number-validation-methods)

MethodDescription`->min($value)`Minimum numeric value allowed.`->max($value)`Maximum numeric value allowed.`->integer()`Must be an integer.`->float()`Must be a float (or an integer is also accepted).### 🗂️ File Validation Methods

[](#️-file-validation-methods)

Use after `Validate::file('input_name')`.

MethodDescription`->min_size($kb)`Minimum size in **kilobytes (KB)**.`->max_size($kb)`Maximum size in **kilobytes (KB)**.`->allowed_extension($exts)`Allowed file extensions (string or array).`->allowed_mime($mimes)`Allowed MIME types (string or array).### 🔧 Custom Validation

[](#-custom-validation)

```
->custom(callable $callback, string $errorMessage)
```

Run any custom logic. If it fails, the provided error message is returned.

Example:

```
->custom(fn($v) => strlen($v) % 2 === 0, 'Length must be even.')
```

### 🚦 Final Step

[](#-final-step)

`->run()`Executes all validation rules and returns an array of error messages.

#### 🧪 Examples

[](#-examples)

##### Validate String

[](#validate-string)

```
$errors = Validate::string('Hello123!')
    ->min_length(5)
    ->max_length(10)
    ->uppercase()
    ->lowercase()
    ->has_number()
    ->special_character()
    ->run();
```

##### Validate Number

[](#validate-number)

```
$errors = Validate::number(5.5)
    ->min(0)
    ->max(10)
    ->float()
    ->run();
```

##### Validate File Upload

[](#validate-file-upload)

```
$errors = Validate::file('image')
    ->min_size(100) // 100KB
    ->max_size(2048) // 2MB
    ->allowed_extension(['jpg', 'png'])
    ->allowed_mime(['image/jpeg', 'image/png'])
    ->run();
```

#### 🧼 Notes

[](#-notes)

`run()` always returns an array. If valid, it will be an empty array.

File size is automatically handled in kilobytes.

You can extend this class easily with more rules or by subclassing.

Let me know if you'd like a version of this in a .md file or integrated into a documentation tool.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance50

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

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

365d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/72742b6d920009945cf5556377e410baf5155a3fb1399f475300f19e9652a059?d=identicon)[ongom](/maintainers/ongom)

### Embed Badge

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

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

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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