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 1w 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

23

—

LowBetter than 25% of packages

Maintenance43

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity38

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

456d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/34609015?v=4)[ongom](/maintainers/ongom)[@ongom](https://github.com/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

[toplan/laravel-sms

A mobile phone number validation solution based on laravel

83580.2k2](/packages/toplan-laravel-sms)[drupal/coder

Coder is a library to review Drupal code.

3046.8M629](/packages/drupal-coder)[hyperf/validation

hyperf validation

122.2M213](/packages/hyperf-validation)[udokmeci/yii2-phone-validator

Modern Yii2 Phone validator wrapper on top of PhoneNumberUtil library also used by Android devices

36227.5k1](/packages/udokmeci-yii2-phone-validator)[snowcap/vat-validation

EU VAT number validation

10112.3k](/packages/snowcap-vat-validation)

PHPackages © 2026

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