PHPackages                             maplephp/validate - 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. maplephp/validate

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

maplephp/validate
=================

User-friendly input validation library.

v2.0.1(2mo ago)24865Apache-2.0PHPPHP &gt;=8.0CI passing

Since Nov 29Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/MaplePHP/Validate)[ Packagist](https://packagist.org/packages/maplephp/validate)[ Docs](https://wazabii.se)[ RSS](/packages/maplephp-validate/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (16)Used By (5)

MaplePHP - Validation
=====================

[](#maplephp---validation)

MaplePHP - Validation is a lightweight and powerful PHP library designed to simplify the validation of various data inputs. Whether you're verifying if a value is a valid email or phone number, ensuring string lengths, or performing more advanced checks like credit card numbers and dates, MaplePHP - Validation offers a comprehensive and intuitive approach. With its wide range of built-in validators and simple syntax, it makes handling complex validation tasks easier, leading to cleaner and more reliable code.

---

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

[](#installation)

Install the library via Composer:

```
composer require maplephp/validate
```

---

Getting Started
---------------

[](#getting-started)

You can validate values by instantiating the `Validator` class. There are two ways to do this:

```
use MaplePHP\Validate\Validator;

// Option 1: Create an instance
$inp = new Validator("Lorem ipsum dolor");
var_dump($inp->length(1, 200)); // true

// Option 2: Use the static method for cleaner syntax
$valid = Validator::value("Lorem ipsum dolor")->length(1, 200);
var_dump($valid); // true
```

---

Validating Nested Data
----------------------

[](#validating-nested-data)

You can traverse nested arrays or objects and validate specific values using dot notation:

```
$inp = new Validator([
  "user" => [
    "name" => "John Doe",
    "email" => "john.doe@gmail.com",
  ]
]);

$valid = $inp->eq("user.name")->length(1, 200);

var_dump($valid); // true
```

> 💡 You can also use `validateInData()` for more dynamic validations:

```
$valid = $inp->validateInData("user.name", "length", [1, 200]);
```

---

Using the Chain validations
---------------------------

[](#using-the-chain-validations)

The `ValidationChain` class allows you to chain multiple validations on a single value and check the overall result:

```
use MaplePHP\Validate\ValidationChain;

$validPool = new ValidationChain("john.doe@gmail.com");

$validPool->isEmail()
    ->length(1, 200)
    ->endsWith(".com");

$isValid = $validPool->isValid();
// $hasError = $validPool->hasError();

var_dump($isValid); // true
```

> 🧠 `ValidationChain` is useful when you want to collect and evaluate multiple validation rules at once.

Validations
-----------

[](#validations)

### Required field

[](#required-field)

```
Validator::value("Lorem ipsum dolor")->isRequired();
```

### Check if there is any value (even if it's 0)

[](#check-if-there-is-any-value-even-if-its-0)

```
Validator::value(0)->hasValue();
```

### Check string length (min, max)

[](#check-string-length-min-max)

- **Min only**:

```
Validator::value("Lorem ipsum dolor")->length(1);
```

- **Min and Max**:

```
Validator::value("Lorem ipsum dolor")->length(1, 160);
```

### Check if string has an exact length

[](#check-if-string-has-an-exact-length)

```
Validator::value("Lorem ipsum dolor")->isLengthEqualTo(10);
```

### Check if value equals exactly to or not equals another value

[](#check-if-value-equals-exactly-to-or-not-equals-another-value)

- **Equals**: Strict data type validation check if equals to expected value

```
Validator::value("Lorem ipsum dolor")->isEqualTo("Lorem ipsum dolor");
```

- **Loosely Equals**: Flexible data type validation check if loosely equals to expected value

```
Validator::value("Lorem ipsum dolor")->isLooselyEqualTo("Lorem ipsum dolor");
```

- **Not equals**: Strict data type validation check if not equals to expected value

```
Validator::value("Lorem ipsum dolor")->isNotEqualTo("Lorem ipsum");
```

- **Loosely Not equals**: Flexible data type validation check if loosely not equals to expected value

```
Validator::value("Lorem ipsum dolor")->isLooselyNotEqualTo("Lorem ipsum");
```

- **More than**:

```
Validator::value(200)->isMoreThan(100);
```

- **Less than**:

```
Validator::value(100)->isLessThan(200);
```

- **Contains**:

```
Validator::value("Lorem ipsum dolor")->contains("ipsum");
```

- **Starts with**:

```
Validator::value("Lorem ipsum dolor")->startsWith("Lorem");
```

- **Ends with**:

```
Validator::value("Lorem ipsum dolor")->endsWith("dolor");
```

### Validate if it's a valid email

[](#validate-if-its-a-valid-email)

```
Validator::value("john@gmail.com")->isEmail();
```

### Validate if it's a valid phone number

[](#validate-if-its-a-valid-phone-number)

Allows numbers and special characters ("-", "+", " ").

```
Validator::value("+46709676040")->isPhone();
```

### Validate Swedish personal number (personnel)

[](#validate-swedish-personal-number-personnel)

```
Validator::value("198808213412")->isSocialNumber();
```

### Validate Swedish organization number

[](#validate-swedish-organization-number)

```
Validator::value("197511043412")->isOrgNumber();
```

### Validate credit card number

[](#validate-credit-card-number)

```
Validator::value("1616523623422334")->isCreditCard();
```

### Validate VAT number

[](#validate-vat-number)

```
Validator::value("SE8272267913")->isVatNumber();
```

### Check if value is a valid float

[](#check-if-value-is-a-valid-float)

```
Validator::value(3.1415)->isFloat();
```

### Check if value is a valid integer

[](#check-if-value-is-a-valid-integer)

```
Validator::value(42)->isInt();
```

### Check if value is a valid number (numeric)

[](#check-if-value-is-a-valid-number-numeric)

```
Validator::value(42)->isNumber();
```

### Check if value is positive or negative

[](#check-if-value-is-positive-or-negative)

- **Positive**:

```
Validator::value(20)->isPositive();
```

- **Negative**:

```
Validator::value(-20)->isNegative();
```

### Check if value is a valid version number

[](#check-if-value-is-a-valid-version-number)

```
// True === validate as a semantic Versioning, e.g. 1.0.0
Validator::value("1.0.0")->isValidVersion(true);
```

### Compare version with another version

[](#compare-version-with-another-version)

```
Validator::value("1.0.0")->versionCompare("2.0.0", '>=');
```

### Validate password (lossy or strict)

[](#validate-password-lossy-or-strict)

- **Lossy password (minimum character set)**:

```
Validator::value("password123")->isLossyPassword(8);
```

- **Strict password** (requires at least one lowercase, uppercase, digit, and special character):

```
Validator::value("Password#123!")->isStrictPassword(8);
```

### Validate if value is string and contains only A-Z

[](#validate-if-value-is-string-and-contains-only-a-z)

- **Both cases**:

```
Validator::value("HelloWorld")->atoZ();
```

- **Lowercase only**:

```
Validator::value("helloworld")->lowerAtoZ();
```

- **Uppercase only**:

```
Validator::value("HELLOWORLD")->upperAtoZ();
```

### Check if it's a valid hex color code

[](#check-if-its-a-valid-hex-color-code)

```
Validator::value("#000000")->hex();
```

### Check if it's a valid date

[](#check-if-its-a-valid-date)

As default you can validate against a date format like this "Y-m-d"

```
Validator::value("2022-02-13")->isDate();
```

Custom date validation

```
Validator::value("2022/02/13 14:15")->isDate(Y/m/d H:i);
```

### Check if it's a valid date and time

[](#check-if-its-a-valid-date-and-time)

```
Validator::value("2022-02-13 14:15:58")->isDateWithTime();
```

### Check if it's a valid time

[](#check-if-its-a-valid-time)

Validate hour and minutes

```
Validator::value("14:15")->isTime();
```

Validate hour, minutes and seconds

```
Validator::value("14:15:58")->isTime(true);
```

### Check if someone is at least a certain age

[](#check-if-someone-is-at-least-a-certain-age)

```
Validator::value("1988-05-22")->isAge(18);
```

### Check if it's a valid domain name

[](#check-if-its-a-valid-domain-name)

```
Validator::value("example.com")->isDomain();
```

### Check if it's a valid URL (http/https is required)

[](#check-if-its-a-valid-url-httphttps-is-required)

```
Validator::value("https://example.com/page")->isUrl();
```

### Check if it's a valid DNS entry

[](#check-if-its-a-valid-dns-entry)

```
Validator::value("example.com")->isDns();
```

### Validate file and directory properties

[](#validate-file-and-directory-properties)

- **Check if it's a valid file**:

```
Validator::value("/path/to/file.txt")->isFile();
```

- **Check if it's a directory**:

```
Validator::value("/path/to/directory")->isDir();
```

- **Check if it's writable**:

```
Validator::value("/path/to/file.txt")->isWritable();
```

- **Check if it's readable**:

```
Validator::value("/path/to/file.txt")->isReadable();
```

### Validate ZIP code (with custom length)

[](#validate-zip-code-with-custom-length)

```
Validator::value("12345")->isZip(5);
```

### Validate if value matches a pattern (regex)

[](#validate-if-value-matches-a-pattern-regex)

```
Validator::value("abc")->pregMatch("a-zA-Z");
```

Validate Arrays
---------------

[](#validate-arrays)

### Check if is an array

[](#check-if-is-an-array)

```
Validator::value(["Apple", "Orange", "Lemon"])->isArray();
```

### Check if array is empty

[](#check-if-array-is-empty)

```
Validator::value(["Apple", "Orange", "Lemon"])->isArrayEmpty();
```

### Strict data type validation check if value exists in given array

[](#strict-data-type-validation-check-if-value-exists-in-given-array)

```
Validator::value(["Apple", "Orange", "Lemon"])->isInArray();
```

### Flexible data type validation check if value exists in given array

[](#flexible-data-type-validation-check-if-value-exists-in-given-array)

```
Validator::value(["Apple", "Orange", "Lemon"])->isLooselyInArray();
```

### Strict data type validation check if key exists in array

[](#strict-data-type-validation-check-if-key-exists-in-array)

```
Validator::value(["Apple", "Orange", "Lemon"])->keyExists();
```

### Check if all items in array is truthy

[](#check-if-all-items-in-array-is-truthy)

```
Validator::value(["1", true, "Lemon"])->itemsAreTruthy();
```

### Check if truthy item exist in array

[](#check-if-truthy-item-exist-in-array)

```
Validator::value(["1", false, "Lemon"])->hasTruthyItem();
```

### Check if array count is equal to length

[](#check-if-array-count-is-equal-to-length)

```
Validator::value(["Apple", "Orange", "Lemon"])->isCountEqualTo(3);
```

### Check if array count is more than the length

[](#check-if-array-count-is-more-than-the-length)

```
Validator::value(["Apple", "Orange", "Lemon"])->isCountMoreThan(1);
```

### Check if array count is less than the length

[](#check-if-array-count-is-less-than-the-length)

```
Validator::value(["Apple", "Orange", "Lemon"])->isCountLessThan(4);
```

### Check if value is a valid float

[](#check-if-value-is-a-valid-float-1)

```
Validator::value("Lorem ipsum dolor")->isString();
```

Validate types
--------------

[](#validate-types)

### Check if value is a valid float

[](#check-if-value-is-a-valid-float-2)

```
Validator::value("Lorem ipsum dolor")->isString();
```

### Check if value is a valid float

[](#check-if-value-is-a-valid-float-3)

```
Validator::value(3.1415)->isFloat();
```

### Check if value is a valid integer

[](#check-if-value-is-a-valid-integer-1)

```
Validator::value(42)->isInt();
```

- **Is Boolean**:

```
Validator::value(true)->isBool();
```

- **Is Boolean-like value** (e.g., "yes", "no", "1", "0"):

```
Validator::value("yes")->isBoolVal();
```

- **Array**:

```
Validator::value([1, 2, 3])->isArray();
```

- **Object**:

```
Validator::value($obj)->isObject();
```

- **Resource**:

```
Validator::value($resource)->isResource();
```

- **Json**:

```
Validator::value($jsonStr)->isJson();
```

- **HTML Document**:

```
Validator::value($jsonStr)->isFullHtml();
```

HTTP status code validation
---------------------------

[](#http-status-code-validation)

#### Strict data type validation check if value is a valid HTTP status code

[](#strict-data-type-validation-check-if-value-is-a-valid-http-status-code)

```
Validator::value(403)->isHttpStatusCode();
```

#### Strict data type validation check if value is HTTP 200 OK

[](#strict-data-type-validation-check-if-value-is-http-200-ok)

```
Validator::value(200)->isHttp200();
```

#### Strict data type validation check if value is a 2xx success HTTP code

[](#strict-data-type-validation-check-if-value-is-a-2xx-success-http-code)

```
Validator::value(210)->isHttpSuccess();
```

#### Strict data type validation check if value is a 4xx client error HTTP code

[](#strict-data-type-validation-check-if-value-is-a-4xx-client-error-http-code)

```
Validator::value(403)->isHttpClientError();
```

#### Strict data type validation check if value is a 5xx server error HTTP code

[](#strict-data-type-validation-check-if-value-is-a-5xx-server-error-http-code)

```
Validator::value(500)->isHttpServerError();
```

### Validate using multiple methods (one or all must match)

[](#validate-using-multiple-methods-one-or-all-must-match)

- **Validate if one method passes**:

```
Validator::value("12345")->oneOf(['isInt' => []]);
```

- **Validate if all methods pass**:

```
Validator::value("12345")->allOf(['isInt' => [], 'length' => [5]]);
```

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance85

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 69.3% 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 ~62 days

Recently: every ~86 days

Total

14

Last Release

86d ago

Major Versions

v1.2.1 → v2.0.02026-01-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/724b188e785081275926c5b9c07082e2b3f4afb797efdda61eb1630457e17824?d=identicon)[wazabii](/maintainers/wazabii)

---

Top Contributors

[![wazabii8](https://avatars.githubusercontent.com/u/6400238?v=4)](https://github.com/wazabii8 "wazabii8 (52 commits)")[![CreativeWaDev](https://avatars.githubusercontent.com/u/153771800?v=4)](https://github.com/CreativeWaDev "CreativeWaDev (14 commits)")[![danielRConsid](https://avatars.githubusercontent.com/u/169045496?v=4)](https://github.com/danielRConsid "danielRConsid (9 commits)")

---

Tags

validationdatainputvalidate request

### Embed Badge

![Health badge](/badges/maplephp-validate/health.svg)

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

###  Alternatives

[nilportugues/validator

An efficient data validator for PHP

131.5k](/packages/nilportugues-validator)

PHPackages © 2026

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