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

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

assegaiphp/validation
=====================

Introducing the AssegaiPHP Validation package, the ultimate tool for ensuring the integrity and accuracy of your application's data. With this package, you can easily implement validation rules for incoming data, whether it be from a form submission, API request, or any other source. The package utilizes a simple, yet powerful syntax that allows you to specify a wide range of validation rules with ease. Additionally, the package integrates seamlessly with the AssegaiPHP framework, making it an essential addition to any AssegaiPHP project. With this package, you'll have peace of mind knowing that your application is receiving clean and accurate data every time.

0.3.2(3y ago)0228↓18.9%2MITPHPPHP ^8.2

Since Feb 3Pushed 2y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (5)Versions (5)Used By (2)

 [![Assegai Logo](https://camo.githubusercontent.com/d7dab2658d76e460e31be249de2fe5d420f7a7237eb9f2a315f83123632a3b6c/68747470733a2f2f617373656761697068702e636f6d2f696d616765732f6c6f676f732f6c6f676f2d63726f707065642e706e67)](https://assegaiphp.com/)

A progressive [PHP](https://php.net) framework for building efficient and scalable server-side applications.

AssegaiPHP Validation
=====================

[](#assegaiphp-validation)

Welcome to the AssegaiPHP validation package! This package is designed to provide a simple and easy-to-use solution for validating data in your AssegaiPHP projects.

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

[](#installation)

To install this package, run the following command in your project's root directory:

```
composer require assegaiphp/validation
```

Basic Usage
-----------

[](#basic-usage)

To use this package, simply import the `Assegai\Validation\Validator` class and create a new instance. You can then use the `validate()` method to check if a value or array of values meet the specified criteria.

```
use Assegai\Validation\Validator;

$validator = new Validator();
$isValid = $validator->validate($value, 'required|email');
```

The second argument to the `validate()` method is a string containing the validation rules to apply, separated by the `|` character. In the example above, the required and email rules are applied.

### Create a Validation Rule

[](#create-a-validation-rule)

```
use Assegai\Validation\Interfaces\IValidationRule;

class MyCustomValidationRule extends IValidationRule
{
  public function passes(mixed $value): bool
  {
    // validate the value
  }

  public function getErrorMessage(): string
  {
    return 'The value is invalid.';
  }
}
```

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

[](#available-rules)

This package comes with a number of built-in validation rules, including:

- `alpha`: value must contain only alphabetic characters
- `alnum`: value must contain only alphanumeric characters
- `between:n,m`: value must be between n and m (inclusive)
- `domain`: value must be a valid domain name
- `email`: value must be a valid email address
- `equalTo:n`: value must be equal to n
- `float`: value must be a floating point number
- `inlist:l`: value is in a specific list of allowed values
- `integer`: value must be an integer
- `maxLength:n`: value must be no more than n characters long
- `max:n`: value does not exceed a maximum value, n
- `minLength:n`: value must be at least n characters long
- `min:n`: value is at least a certain value, n
- `notEqualTo:n`: value must not be equal to n
- `notinlist:l`: value is not in a specific list of disallowed values
- `numeric`: value must be a number
- `regex:n`: value must match the given regex pattern n
- `required`: value must be present
- `string`: value must be a string
- `url`: value must be a valid url

You can also create custom validation rules by extending the Assegai\\Validation\\Rule class and implementing the validate() method.

Validation Attributes
---------------------

[](#validation-attributes)

AttributeDescriptionCommon validation attributes\#\[IsDefined(mixed $value)\]Checks if value is defined (!== undefined, !== null). This is the only attribute that ignores skipMissingProperties option.\#\[IsOptional\]Checks if given value is empty (=== null, === undefined) and if so, ignores all the validators on the property.\#\[Equals(mixed $comparison)\]Checks if value equals ("===") comparison.\#\[NotEquals(mixed $comparison)\]Checks if value not equal ("!==") comparison.\#\[IsEmpty\]Checks if given value is empty (=== '', === null, === undefined).\#\[IsNotEmpty\]Checks if given value is not empty (!== '', !== null, !== undefined).\#\[IsIn(array $values\]Checks if value is in an array of allowed values.\#\[IsNotIn(array $values)\]Checks if value is not in an array of disallowed values.Type validation attributes\#\[IsBoolean\]Checks if a value is a boolean.\#\[IsDate\]Checks if the value is a date.\#\[IsString\]Checks if the value is a string.\#\[IsNumber(IsNumberOptions $options)\]Checks if the value is a number.\#\[IsInt\]Checks if the value is an integer number.\#\[IsArray\]Checks if the value is an array\#\[IsEnum(string $enum)\]Checks if the value is a valid enumNumber validation attributes\#\[IsDivisibleBy(num: number)\]Checks if the value is a number that's divisible by another.\#\[IsPositive\]Checks if the value is a positive number greater than zero.\#\[IsNegative\]Checks if the value is a negative number smaller than zero.\#\[Min(min: number)\]Checks if the given number is greater than or equal to given number.\#\[Max(max: number)\]Checks if the given number is less than or equal to given number.Date validation attributes\#\[MinDate(string $date\]Checks if the value is a date that's after the specified date.\#\[MaxDate(string $date\]Checks if the value is a date that's before the specified date.String-type validation attributes\#\[IsBooleanString\]Checks if a string is a boolean (e.g. is "true" or "false" or "1", "0").\#\[IsDateString\]Alias for @IsISO8601().\#\[IsNumberString(?IsNumericOptions $options)\]Checks if a string is a number.String validation attributes\#\[Contains(seed: string)\]Checks if the string contains the seed.\#\[NotContains(seed: string)\]Checks if the string not contains the seed.\#\[IsAlpha\]Checks if the string contains only letters (a-zA-Z).\#\[IsAlphanumeric\]Checks if the string contains only letters and numbers.\#\[IsDecimal(?IsDecimalOptions $options)\]Checks if the string is a valid decimal value. Default IsDecimalOptions are force\_decimal=False, decimal\_digits: '1,', locale: 'en-US'\#\[IsAscii\]Checks if the string contains ASCII chars only.\#\[IsBase32\]Checks if a string is base32 encoded.\#\[IsBase58\]Checks if a string is base58 encoded.\#\[IsBase64(?IsBase64Options $options)\]Checks if a string is base64 encoded.\#\[IsIBAN\]Checks if a string is a IBAN (International Bank Account Number).\#\[IsBIC\]Checks if a string is a BIC (Bank Identification Code) or SWIFT code.\#\[IsByteLength(int $min, ?int $max)\]Checks if the string's length (in bytes) falls in a range.\#\[IsCreditCard\]Checks if the string is a credit card.\#\[IsCurrency(?IsCurrencyOptions $options)\]Checks if the string is a valid currency amount.\#\[IsISO4217CurrencyCode\]Checks if the string is an ISO 4217 currency code.\#\[IsEthereumAddress\]Checks if the string is an Ethereum address using basic regex. Does not validate address checksums.\#\[IsBtcAddress\]Checks if the string is a valid BTC address.\#\[IsDataURI\]Checks if the string is a data uri format.\#\[IsEmail(?IsEmailOptions $options)\]Checks if the string is an email.\#\[IsFQDN(?IsFQDNOptions $options)\]Checks if the string is a fully qualified domain name (e.g. domain.com).\#\[IsFullWidth\]Checks if the string contains any full-width chars.\#\[IsHalfWidth\]Checks if the string contains any half-width chars.\#\[IsVariableWidth\]Checks if the string contains a mixture of full and half-width chars.\#\[IsHexColor\]Checks if the string is a hexadecimal color.\#\[IsHSL\]Checks if the string is an HSL color based on CSS Colors Level 4 specification.\#\[IsRgbColor(?IsRgbOptions $options)\]Checks if the string is a rgb or rgba color.\#\[IsIdentityCard(?string $locale)\]Checks if the string is a valid identity card code.\#\[IsPassportNumber(?string $countryCode)\]Checks if the string is a valid passport number relative to a specific country code.\#\[IsPostalCode(?string $locale)\]Checks if the string is a postal code.\#\[IsHexadecimal\]Checks if the string is a hexadecimal number.\#\[IsOctal\]Checks if the string is a octal number.\#\[IsMACAddress(?IsMACAddressOptions $options)\]Checks if the string is a MAC Address.\#\[IsIP(?IPVersion $version)\]Checks if the string is an IP (version 4 or 6).\#\[IsPort()\]Checks if the string is a valid port number.\#\[IsISBN(?ISBNVersion $version)\]Checks if the string is an ISBN (version 10 or 13).\#\[IsEAN\]Checks if the string is an if the string is an EAN (European Article Number).\#\[IsISIN\]Checks if the string is an ISIN (stock/security identifier).\#\[IsISO8601(?IsISO8601Options $options)\]Checks if the string is a valid ISO 8601 date format. Use the option strict = true for additional checks for a valid date.\#\[IsJSON\]Checks if the string is valid JSON.\#\[IsJWT\]Checks if the string is valid JWT.\#\[IsObject\]Checks if the object is valid Object (null, functions, arrays will return false).\#\[IsNotEmptyObject\]Checks if the object is not empty.\#\[IsLowercase\]Checks if the string is lowercase.\#\[IsLatLong\]Checks if the string is a valid latitude-longitude coordinate in the format lat, long.\#\[IsLatitude\]Checks if the string or number is a valid latitude coordinate.\#\[IsLongitude\]Checks if the string or number is a valid longitude coordinate.\#\[IsMobilePhone(string $locale)\]Checks if the string is a mobile phone number.\#\[IsISO31661Alpha2\]Checks if the string is a valid ISO 3166-1 alpha-2 officially assigned country code.\#\[IsISO31661Alpha3\]Checks if the string is a valid ISO 3166-1 alpha-3 officially assigned country code.\#\[IsLocale\]Checks if the string is a locale.\#\[IsPhoneNumber(string $region)\]Checks if the string is a valid phone number using `giggsey/libphonenumber-for-php`.\#\[IsMongoId\]Checks if the string is a valid hex-encoded representation of a MongoDB ObjectId.\#\[IsMultibyte\]Checks if the string contains one or more multibyte chars.\#\[IsNumberString(?IsNumericOptions $options)\]Checks if the string is numeric.\#\[IsSurrogatePair\]Checks if the string contains any surrogate pairs chars.\#\[IsTaxId\]Checks if the string is a valid tax ID. Default locale is en-US.\#\[IsUrl(?IsURLOptions $options)\]Checks if the string is a URL.\#\[IsMagnetURI\]Checks if the string is a magnet uri format.\#\[IsUUID(?UUIDVersion $version)\]Checks if the string is a UUID (version 3, 4, 5 or all ).\#\[IsFirebasePushId\]Checks if the string is a Firebase Push ID\#\[IsUppercase\]Checks if the string is uppercase.\#\[Length(int $min, ?int $max)\]Checks if the string's length falls in a range.\#\[MinLength(int $min)\]Checks if the string's length is not less than given number.\#\[MaxLength(int $max)\]Checks if the string's length is not more than given number.\#\[Matches(RegExp $pattern, ?string $modifiers)\]Checks if string matches the pattern. Either matches('foo', /foo/i) or matches('foo', 'foo', 'i').\#\[IsMilitaryTime\]Checks if the string is a valid representation of military time in the format HH:MM.\#\[IsTimeZone\]Checks if the string represents a valid IANA time-zone.\#\[IsHash(string $algorithm)\]Checks if the string is a hash The following types are supported:md4, md5, sha1, sha256, sha384, sha512, ripemd128, ripemd160, tiger128, tiger160, tiger192, crc32, crc32b.\#\[IsMimeType\]Checks if the string matches to a valid MIME type format\#\[IsSemVer\]Checks if the string is a Semantic Versioning Specification (SemVer).\#\[IsISSN(?IsISSNOptions $options)\]Checks if the string is a ISSN.\#\[IsISRC\]Checks if the string is a ISRC.\#\[IsRFC3339\]Checks if the string is a valid RFC 3339 date.\#\[IsStrongPassword(?IsStrongPasswordOptions $options)\]Checks if the string is a strong password.Array validation attributes\#\[ArrayContains(array $values)\]Checks if array contains all values from the given array of values.\#\[ArrayNotContains(array $values)\]Checks if array does not contain any of the given values.\#\[ArrayNotEmpty\]Checks if given array is not empty.\#\[ArrayMinSize(int $min)\]Checks if the array's length is greater than or equal to the specified number.\#\[ArrayMaxSize(int $max)\]Checks if the array's length is less or equal to the specified number.\#\[ArrayUnique(?callable $identifier)\]Checks if all array's values are unique. Comparison for objects is reference-based. Optional function can be speciefied which return value will be used for the comparsion.Object validation attributes\#\[IsInstance(mixed $value)\]Checks if the property is an instance of the passed value.Other attributes\#\[Allow\]Prevent stripping off the property when no other constraint is specified for it.Error Handling
--------------

[](#error-handling)

If the validate() method returns false, you can use the getErrors() method to retrieve an array of error messages.

```
if (!$isValid)
{
  $errors = $validator->getErrors();
  // handle errors
}
```

Further Reading
---------------

[](#further-reading)

For more information on how to use this package, please see the full [documentation](https://assegaiphp.com/gudie/techniques/validation). Thank you for using the AssegaiPHP.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82.2% 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 ~4 days

Total

3

Last Release

1183d ago

PHP version history (2 changes)0.3.0PHP &gt;=8.2

0.3.1PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/b56f1a86c97a44aa8b6e391bdfff3e41895f2262f6fd9295195806a068921e23?d=identicon)[amasiye](/maintainers/amasiye)

---

Top Contributors

[![amasiyelr](https://avatars.githubusercontent.com/u/141437318?v=4)](https://github.com/amasiyelr "amasiyelr (60 commits)")[![amasiye](https://avatars.githubusercontent.com/u/5607605?v=4)](https://github.com/amasiye "amasiye (13 commits)")

###  Code Quality

TestsCodeception

### Embed Badge

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

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

###  Alternatives

[ronanguilloux/isocodes

PHP library - Validators for standards from ISO, International Finance, Public Administrations, GS1, Book and Music Industries, Phone numbers &amp; Zipcodes for many countries

8013.3M23](/packages/ronanguilloux-isocodes)[borales/yii2-phone-input

Yii2 International telephone numbers - Asset Bundle, Behavior, Validator, Widget

1341.6M6](/packages/borales-yii2-phone-input)[ipub/phone

Phone helper &amp; validator for Nette Framework

1285.3k6](/packages/ipub-phone)[yii2mod/yii2-validators

Collection of useful validators for Yii Framework 2.0

1816.8k](/packages/yii2mod-yii2-validators)

PHPackages © 2026

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