PHPackages                             oranzh/gump - 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. oranzh/gump

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

oranzh/gump
===========

Only for me, this is from Wixel

029PHP

Since Aug 14Pushed 3y agoCompare

[ Source](https://github.com/Oranzh/GUMP)[ Packagist](https://packagist.org/packages/oranzh/gump)[ RSS](/packages/oranzh-gump/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Getting started
===============

[](#getting-started)

GUMP is a standalone PHP data validation and filtering class that makes validating any data easy and painless without the reliance on a framework. GUMP is open-source since 2013.

Supports wide range of PHP versions (**php7.1** to **php8.1**) and **ZERO dependencies**!

[![Total Downloads](https://camo.githubusercontent.com/37408f1d6ddbecfc0f737b9ddf0b9a33015a614eaee45f461e638a03d8873551/68747470733a2f2f706f7365722e707567782e6f72672f776978656c2f67756d702f646f776e6c6f616473)](https://packagist.org/packages/wixel/gump)[![Latest Stable Version](https://camo.githubusercontent.com/97738b1704250223bb298fedc82cefd8f0f088468c3de259e8bea614f9982f23/68747470733a2f2f706f7365722e707567782e6f72672f776978656c2f67756d702f762f737461626c65)](https://packagist.org/packages/wixel/gump)[![Build Status](https://github.com/wixel/gump/actions/workflows/ci.yml/badge.svg)](https://github.com/wixel/gump/actions/workflows/ci.yml/badge.svg)[![Coverage Status](https://camo.githubusercontent.com/99d6595f625d6e53278f8442d3d5b8688ba0ee6be751009a5c0954a9c234e1f5/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f576978656c2f47554d502f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Wixel/GUMP?branch=master)[![License](https://camo.githubusercontent.com/fc7895d8c6a9df22902abafa76ed8e1e1f3051240a25efdb8d3a552dc13c8b72/68747470733a2f2f706f7365722e707567782e6f72672f776978656c2f67756d702f6c6963656e7365)](https://packagist.org/packages/wixel/gump)

#### Install with composer

[](#install-with-composer)

```
composer require wixel/gump

```

### Short format example for validations

[](#short-format-example-for-validations)

```
$is_valid = GUMP::is_valid(array_merge($_POST, $_FILES), [
    'username'       => 'required|alpha_numeric',
    'password'       => 'required|between_len,4;100',
    'avatar'         => 'required_file|extension,png;jpg',
    'tags'           => 'required|alpha_numeric', // ['value1', 'value3']
    'person.name'    => 'required',               // ['person' => ['name' => 'value']]
    'persons.*.age'  => 'required'                // ['persons' => [
                                                  //      ['name' => 'value1', 'age' => 20],
                                                  //      ['name' => 'value2']
                                                  // ]]
]);

// 1st array is rules definition, 2nd is field-rule specific error messages (optional)
$is_valid = GUMP::is_valid(array_merge($_POST, $_FILES), [
    'username' => ['required', 'alpha_numeric'],
    'password' => ['required', 'between_len' => [6, 100]],
    'avatar'   => ['required_file', 'extension' => ['png', 'jpg']]
], [
    'username' => ['required' => 'Fill the Username field please.'],
    'password' => ['between_len' => '{field} must be between {param[0]} and {param[1]} characters.'],
    'avatar'   => ['extension' => 'Valid extensions for avatar are: {param}'] // "png, jpg"
]);

if ($is_valid === true) {
    // continue
} else {
    var_dump($is_valid); // array of error messages
}
```

### Short format example for filtering

[](#short-format-example-for-filtering)

```
$filtered = GUMP::filter_input([
    'field'       => ' text ',
    'other_field' => 'Cool Title'
], [
    'field'       => ['trim', 'upper_case'],
    'other_field' => 'slug'
]);

var_dump($filtered['field']); // result: "TEXT"
var_dump($filtered['other_field']); // result: "cool-title"
```

### Long format example

[](#long-format-example)

```
$gump = new GUMP();

// set validation rules
$gump->validation_rules([
    'username'    => 'required|alpha_numeric|max_len,100|min_len,6',
    'password'    => 'required|max_len,100|min_len,6',
    'email'       => 'required|valid_email',
    'gender'      => 'required|exact_len,1|contains,m;f',
    'credit_card' => 'required|valid_cc'
]);

// set field-rule specific error messages
$gump->set_fields_error_messages([
    'username'      => ['required' => 'Fill the Username field please, its required.'],
    'credit_card'   => ['extension' => 'Please enter a valid credit card.']
]);

// set filter rules
$gump->filter_rules([
    'username' => 'trim|sanitize_string',
    'password' => 'trim',
    'email'    => 'trim|sanitize_email',
    'gender'   => 'trim',
    'bio'      => 'noise_words'
]);

// on success: returns array with same input structure, but after filters have run
// on error: returns false
$valid_data = $gump->run($_POST);

if ($gump->errors()) {
    var_dump($gump->get_readable_errors()); // ['Field Somefield is required.']
    // or
    var_dump($gump->get_errors_array()); // ['field' => 'Field Somefield is required']
} else {
    var_dump($valid_data);
}
```

⭐ Available Validators
----------------------

[](#star-available-validators)

**Important:** If you use Pipe or Semicolon as parameter value, you **must** use array format.

```
$is_valid = GUMP::is_valid(array_merge($_POST, $_FILES), [
    'field' => 'regex,/partOf;my|Regex/', // NO
    'field' => ['regex' => '/partOf;my|Regex/'] // YES
]);
```

RuleDescription**required**Ensures the specified key value exists and is not empty (not null, not empty string, not empty array).**contains**,one;two;use array format if one of the values contains semicolonsVerify that a value is contained within the pre-defined value set.**contains\_list**,value1;value2Verify that a value is contained within the pre-defined value set. Error message will NOT show the list of possible values.**doesnt\_contain\_list**,value1;value2Verify that a value is contained within the pre-defined value set. Error message will NOT show the list of possible values.**boolean**,strictDetermine if the provided value is a valid boolean. Returns true for: yes/no, on/off, 1/0, true/false. In strict mode (optional) only true/false will be valid which you can combine with boolean filter.**valid\_email**Determine if the provided email has valid format.**max\_len**,240Determine if the provided value length is less or equal to a specific value.**min\_len**,4Determine if the provided value length is more or equal to a specific value.**exact\_len**,5Determine if the provided value length matches a specific value.**between\_len**,3;11Determine if the provided value length is between min and max values.**alpha**Determine if the provided value contains only alpha characters.**alpha\_numeric**Determine if the provided value contains only alpha-numeric characters.**alpha\_dash**Determine if the provided value contains only alpha characters with dashed and underscores.**alpha\_numeric\_dash**Determine if the provided value contains only alpha numeric characters with dashed and underscores.**alpha\_numeric\_space**Determine if the provided value contains only alpha numeric characters with spaces.**alpha\_space**Determine if the provided value contains only alpha characters with spaces.**numeric**Determine if the provided value is a valid number or numeric string.**integer**Determine if the provided value is a valid integer.**float**Determine if the provided value is a valid float.**valid\_url**Determine if the provided value is a valid URL.**url\_exists**Determine if a URL exists &amp; is accessible.**valid\_ip**Determine if the provided value is a valid IP address.**valid\_ipv4**Determine if the provided value is a valid IPv4 address.**valid\_ipv6**Determine if the provided value is a valid IPv6 address.**valid\_cc**Determine if the input is a valid credit card number.**valid\_name**Determine if the input is a valid human name.**street\_address**Determine if the provided input is likely to be a street address using weak detection.**iban**Determine if the provided value is a valid IBAN.**date**,d/m/YDetermine if the provided input is a valid date (ISO 8601) or specify a custom format (optional).**min\_age**,18Determine if the provided input meets age requirement (ISO 8601). Input should be a date (Y-m-d).**max\_numeric**,50Determine if the provided numeric value is lower or equal to a specific value.**min\_numeric**,1Determine if the provided numeric value is higher or equal to a specific value.**starts**,ZDetermine if the provided value starts with param.**required\_file**Determine if the file was successfully uploaded.**extension**,png;jpg;gifCheck the uploaded file for extension. Doesn't check mime-type yet.**equalsfield**,other\_field\_nameDetermine if the provided field value equals current field value.**guidv4**Determine if the provided field value is a valid GUID (v4)**phone\_number**Determine if the provided value is a valid phone number.**regex**,/test-\[0-9\]{3}/Custom regex validator.**valid\_json\_string**Determine if the provided value is a valid JSON string.**valid\_array\_size\_greater**,1Check if an input is an array and if the size is more or equal to a specific value.**valid\_array\_size\_lesser**,1Check if an input is an array and if the size is less or equal to a specific value.**valid\_array\_size\_equal**,1Check if an input is an array and if the size is equal to a specific value.

⭐ Available Filters
-------------------

[](#star-available-filters)

Filter rules can also be any PHP native function (e.g.: trim).

FilterDescription**noise\_words**Replace noise words in a string ([http://tax.cchgroup.com/help/Avoiding\_noise\_words\_in\_your\_search.htm](http://tax.cchgroup.com/help/Avoiding_noise_words_in_your_search.htm)).**rmpunctuation**Remove all known punctuation from a string.**urlencode**Sanitize the string by urlencoding characters.**htmlencode**Sanitize the string by converting HTML characters to their HTML entities.**sanitize\_email**Sanitize the string by removing illegal characters from emails.**sanitize\_numbers**Sanitize the string by removing illegal characters from numbers.**sanitize\_floats**Sanitize the string by removing illegal characters from float numbers.**sanitize\_string**Sanitize the string by removing any script tags.**boolean**Converts \['1', 1, 'true', true, 'yes', 'on'\] to true, anything else is false ('on' is useful for form checkboxes).**basic\_tags**Filter out all HTML tags except the defined basic tags.**whole\_number**Convert the provided numeric value to a whole number.**ms\_word\_characters**Convert MS Word special characters to web safe characters. (\[“ ”\] =&gt; ", \[‘ ’\] =&gt; ', \[–\] =&gt; -, \[…\] =&gt; ...)**lower\_case**Converts to lowercase.**upper\_case**Converts to uppercase.**slug**Converts value to url-web-slugs.**trim**Remove spaces from the beginning and end of strings (PHP).

#### Other Available Methods

[](#other-available-methods)

```
/**
 * This is the most flexible validation "executer" because of it's return errors format.
 *
 * Returns bool true when no errors.
 * Returns array of errors with detailed info. which you can then use with your own helpers.
 * (field name, input value, rule that failed and it's parameters).
 */
$gump->validate(array $input, array $ruleset);

/**
 * Filters input data according to the provided filterset
 *
 * Returns array with same input structure but after filters have been applied.
 */
$gump->filter(array $input, array $filterset);

// Sanitizes data and converts strings to UTF-8 (if available), optionally according to the provided field whitelist
$gump->sanitize(array $input, $whitelist = null);

// Override field names in error messages
GUMP::set_field_name('str', 'Street');
GUMP::set_field_names([
    'str' => 'Street',
    'zip' => 'ZIP Code'
]);

// Set custom error messages for rules.
GUMP::set_error_message('required', '{field} is required.');
GUMP::set_error_messages([
    'required'    => '{field} is required.',
    'valid_email' => '{field} must be a valid email.'
]);
```

### Creating your own validators and filters

[](#creating-your-own-validators-and-filters)

Adding custom validators and filters is made easy by using callback functions.

```
/**
 * You would call it like 'equals_string,someString'
 *
 * @param string $field  Field name
 * @param array  $input  Whole input data
 * @param array  $params Rule parameters. This is usually empty array by default if rule does not have parameters.
 * @param mixed  $value  Value.
 *                       In case of an array ['value1', 'value2'] would return one single value.
 *                       If you want to get the array itself use $input[$field].
 *
 * @return bool   true or false whether the validation was successful or not
 */
GUMP::add_validator("equals_string", function($field, array $input, array $params, $value) {
    return $value === $params;
}, 'Field {field} does not equal to {param}.');

/**
 * @param string $value Value
 * @param array  $param Filter parameters (optional)
 *
 * @return mixed  result of filtered value
 */
GUMP::add_filter("upper", function($value, array $params = []) {
    return strtoupper($value);
});
```

Alternately, you can simply create your own class that extends GUMP. You only have to have in mind:

- For filter methods, prepend the method name with "filter\_".
- For validator methods, prepend the method name with "validate\_".

```
class MyClass extends GUMP
{
    protected function filter_myfilter($value, array $params = [])
    {
        return strtoupper($value);
    }

    protected function validate_myvalidator($field, array $input, array $params = [], $value)
    {
        return $input[$field] === 'good_value';
    }
}

$validator = new MyClass();
$validated = $validator->validate($_POST, $rules);
```

Global configuration
--------------------

[](#global-configuration)

This configuration values allows you to change default rules delimiters (e.g.: `required|contains,value1;value2` to `required|contains:value1,value2`).

```
GUMP::$rules_delimiter = '|';

GUMP::$rules_parameters_delimiter = ',';

GUMP::$rules_parameters_arrays_delimiter = ';';
```

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

 Bus Factor1

Top contributor holds 64.8% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/78c6b7ce4476d36bcd632b5b69a32f021fe6c94616b8b1627f727e9a35892062?d=identicon)[Friday](/maintainers/Friday)

---

Top Contributors

[![filisko](https://avatars.githubusercontent.com/u/8798694?v=4)](https://github.com/filisko "filisko (390 commits)")[![sn](https://avatars.githubusercontent.com/u/77145?v=4)](https://github.com/sn "sn (146 commits)")[![roydekleijn](https://avatars.githubusercontent.com/u/1298389?v=4)](https://github.com/roydekleijn "roydekleijn (6 commits)")[![rwitchell](https://avatars.githubusercontent.com/u/5378642?v=4)](https://github.com/rwitchell "rwitchell (6 commits)")[![groucho75](https://avatars.githubusercontent.com/u/1230256?v=4)](https://github.com/groucho75 "groucho75 (5 commits)")[![mazubieta](https://avatars.githubusercontent.com/u/45144667?v=4)](https://github.com/mazubieta "mazubieta (4 commits)")[![pl4g4](https://avatars.githubusercontent.com/u/945246?v=4)](https://github.com/pl4g4 "pl4g4 (4 commits)")[![ib4](https://avatars.githubusercontent.com/u/4975243?v=4)](https://github.com/ib4 "ib4 (4 commits)")[![redian](https://avatars.githubusercontent.com/u/816941?v=4)](https://github.com/redian "redian (3 commits)")[![uacode](https://avatars.githubusercontent.com/u/829319?v=4)](https://github.com/uacode "uacode (3 commits)")[![Oranzh](https://avatars.githubusercontent.com/u/21193565?v=4)](https://github.com/Oranzh "Oranzh (2 commits)")[![adaniello](https://avatars.githubusercontent.com/u/242423?v=4)](https://github.com/adaniello "adaniello (2 commits)")[![cjrupak](https://avatars.githubusercontent.com/u/40754163?v=4)](https://github.com/cjrupak "cjrupak (2 commits)")[![davidmars](https://avatars.githubusercontent.com/u/1409408?v=4)](https://github.com/davidmars "davidmars (2 commits)")[![eko3alpha](https://avatars.githubusercontent.com/u/1705908?v=4)](https://github.com/eko3alpha "eko3alpha (2 commits)")[![innovaweb-dev](https://avatars.githubusercontent.com/u/2601347?v=4)](https://github.com/innovaweb-dev "innovaweb-dev (2 commits)")[![joseluisq](https://avatars.githubusercontent.com/u/1700322?v=4)](https://github.com/joseluisq "joseluisq (2 commits)")[![absherzad](https://avatars.githubusercontent.com/u/1332906?v=4)](https://github.com/absherzad "absherzad (2 commits)")[![rcrowe](https://avatars.githubusercontent.com/u/282571?v=4)](https://github.com/rcrowe "rcrowe (2 commits)")[![scottcase](https://avatars.githubusercontent.com/u/7584815?v=4)](https://github.com/scottcase "scottcase (2 commits)")

### Embed Badge

![Health badge](/badges/oranzh-gump/health.svg)

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

###  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)
