PHPackages                             struktal/struktal-validation - 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. struktal/struktal-validation

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

struktal/struktal-validation
============================

PHP library to validate user inputs for APIs or forms

2.1.3(4mo ago)01.7k↑271.4%1MITPHPPHP &gt;=8CI passing

Since Jul 22Pushed 4mo agoCompare

[ Source](https://github.com/Struktal/struktal-validation)[ Packagist](https://packagist.org/packages/struktal/struktal-validation)[ RSS](/packages/struktal-struktal-validation/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (9)Dependencies (2)Versions (10)Used By (1)

Struktal-Validation
===================

[](#struktal-validation)

This is a PHP library for validating user inputs through APIs or forms.

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

[](#installation)

To install this library, include it in your project using Composer:

```
composer require struktal/validation
```

Usage
-----

[](#usage)

### Basic validation

[](#basic-validation)

To validate a variable against a set of rules, you can best use the `ValidationBuilder` class:

```
use struktal\validation\ValidationBuilder;
use struktal\validation\ValidationException;

$userInput = $_POST["input"];

// Create a validation builder instance
$validatedData = (new ValidationBuilder())
    // Define validation rules
    ->withErrorMessage("Input is missing")
    ->string()
    ->withErrorMessage("Input must be a string")
    ->minLength(5)
    ->withErrorMessage("Input must be at least 5 characters long")
    ->maxLength(10)
    ->withErrorMessage("Input must be at most 10 characters long")
    // Validate the input
    ->validate($userInput, function($e) {
        // Handle validation errors
        echo "Validation failed: " . $e->getMessage();
    });

// Do something with the validated data
```

### Array validation

[](#array-validation)

You can also validate arrays in a similar way:

```
use struktal\validation\ValidationBuilder;
use struktal\validation\ValidationException;

$userInput = $_POST;

$validatedData = (new ValidationBuilder())
    ->withErrorMessage("No POST data provided")
    ->array()
    ->children([
        "input" => (new ValidationBuilder())
            ->withErrorMessage("Input is missing")
            ->string()
            ->build(), // More rules could apply, also with explicit error messages
        "moreInput" => (new ValidationBuilder())
            ->withErrorMessage("More input is missing")
            ->int()
            ->minValue(0)
            ->maxValue(10)
            ->build(),
    ])
    ->withErrorMessage("Invalid POST data")
    ->validate($userInput, function($e) {
        // Handle validation errors
        echo "Validation failed: " . $e->getMessage();
    });

// Do something with the validated data
```

### Database validation

[](#database-validation)

If you use [Struktal/struktal-orm](https://github.com/Struktal/struktal-orm), you can also check whether an object exists in the database. Use the `inDatabase()` method to validate that the user has provided a valid object ID. The method takes a `GenericEntityDAO` object, as well as an optional array for additional filter options as parameters.

Dependencies
------------

[](#dependencies)

This library uses the following dependencies:

- **ext-pdo**
- **struktal-orm** - GitHub: [Struktal/struktal-orm](https://github.com/Struktal/struktal-orm), licensed under [MIT license](https://github.com/Struktal/struktal-orm/blob/main/LICENSE)
- **pest** - GitHub: [pestphp/pest](https://github.com/pestphp/pest), licensed under [MIT license](https://github.com/pestphp/pest/blob/3.x/LICENSE.md)

License
-------

[](#license)

This software is licensed under the MIT license. See the [LICENSE](./LICENSE) file for more information.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance75

Regular maintenance activity

Popularity20

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity42

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

Recently: every ~40 days

Total

9

Last Release

134d ago

Major Versions

1.0.3 → 2.0.02025-09-12

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

2.1.1PHP &gt;=8

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/49905418?v=4)[Jens Ostertag](/maintainers/JensOstertag)[@JensOstertag](https://github.com/JensOstertag)

---

Top Contributors

[![JensOstertag](https://avatars.githubusercontent.com/u/49905418?v=4)](https://github.com/JensOstertag "JensOstertag (28 commits)")

---

Tags

validation

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/struktal-struktal-validation/health.svg)

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

###  Alternatives

[composer/semver

Version comparison library that offers utilities, version constraint parsing and validation.

3.3k522.3M993](/packages/composer-semver)[giggsey/libphonenumber-for-php

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

5.0k159.6M527](/packages/giggsey-libphonenumber-for-php)[respect/validation

The most awesome validation engine ever created for PHP

6.0k39.9M414](/packages/respect-validation)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k39.7M146](/packages/propaganistas-laravel-phone)[opis/json-schema

Json Schema Validator for PHP

65243.6M304](/packages/opis-json-schema)[giggsey/libphonenumber-for-php-lite

A lite version of giggsey/libphonenumber-for-php, which is a PHP Port of Google's libphonenumber

9216.6M76](/packages/giggsey-libphonenumber-for-php-lite)

PHPackages © 2026

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