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

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

deftx/gump
==========

Composer package for Wixel/GUMP

0490PHP

Since May 17Pushed 13y ago1 watchersCompare

[ Source](https://github.com/deftx/GUMP)[ Packagist](https://packagist.org/packages/deftx/gump)[ RSS](/packages/deftx-gump/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#getting-started)

GUMP is a standalone PHP input validation and filtering class.

1. Download GUMP
2. Unzip it and copy the directory into your PHP project directory.

Include it in your project:

```
require "gump.class.php";
```

Methods available:

```
validation_rules(array $rules); // Get or set the validation rules
filter_rules(array $rules); // Get or set the filtering rules
run(array $data); // Runs the filter and validation routines
xss_clean(array $data); // Strips and encodes unwanted characters
sanitize(array $input, $fields = NULL); // Sanitizes data and converts strings to UTF-8 (if available)
validate(array $input, array $ruleset); // Validates input data according to the provided ruleset (see example)
filter(array $input, array $filterset); // Filters input data according to the provided filterset (see example)
get_readable_errors($convert_to_string = false); // Returns human readable error text in an array or string
```

Complete Working Example
========================

[](#complete-working-example)

The following example is part of a registration form, the flow should be pretty standard

```
# Note that filters and validators are separate rule sets and method calls. There is a good reason for this.

require "gump.class.php";

$gump = new GUMP();

$_POST = $gump->sanitize($_POST); // You don't have to sanitize, but it's safest to do so.

$gump->validation_rules(array(
	'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|trim|valid_cc'
));

$gump->filter_rules(array(
	'username' 	  => 'trim|sanitize_string|mysql_escape',
	'password'	  => 'trim|base64',
	'email'    	  => 'trim|sanitize_email',
	'gender'   	  => 'trim',
	'bio'		  => 'noise_words'
));

$validated_data = $gump->run($_POST);

if($validated_data === false) {
	echo $gump->get_readable_errors(true);
} else {
	print_r($validated_data); // validation successful
}
```

Return Values
-------------

[](#return-values)

`run()` returns one of two types:

*ARRAY* containing the successfully validated and filtered data when the validation is successful *FALSE* when the validation has failed

`validate()` returns one of two types:

*AN ARRAY* containing key names and validator names when data does not pass the validation.

You can use this array along with your language helpers to determine what error message to show.

*A BOOLEAN* value of TRUE if the validation was successful.

`filter()` returns the exact array structure that was parsed as the `$input` parameter, the only difference would be the filtered data.

Available Validators
--------------------

[](#available-validators)

- required `Ensures the specified key value exists and is not empty`
- valid\_email `Checks for a valid email address`
- max\_len,n `Checks key value length, makes sure it's not longer than the specified length. n = length parameter.`
- min\_len,n `Checks key value length, makes sure it's not shorter than the specified length. n = length parameter.`
- exact\_len,n `Ensures that the key value length precisely matches the specified length. n = length parameter.`
- alpha `Ensure only alpha characters are present in the key value (a-z, A-Z)`
- alpha\_numeric `Ensure only alpha-numeric characters are present in the key value (a-z, A-Z, 0-9)`
- alpha\_dash `Ensure only alpha-numeric characters + dashes and underscores are present in the key value (a-z, A-Z, 0-9, _-)`
- numeric `Ensure only numeric key values`
- integer `Ensure only integer key values`
- boolean `Checks for PHP accepted boolean values, returns TRUE for "1", "true", "on" and "yes"`
- float `Checks for float values`
- valid\_url `Check for valid URL or subdomain`
- url\_exists `Check to see if the url exists and is accessible`
- valid\_ip `Check for valid generic IP address`
- valid\_ipv4 `Check for valid IPv4 address`
- valid\_ipv6 `Check for valid IPv6 address`
- valid\_cc `Check for a valid credit card number (Uses the MOD10 Checksum Algorithm)`
- valid\_name `Check for a valid format human name`
- contains,n `Verify that a value is contained within the pre-defined value set`

Available Filters
-----------------

[](#available-filters)

Filters can be any PHP function that returns a string. You don't need to create your own if a PHP function exists that does what you want the filter to do.

- sanitize\_string `Remove script tags and encode HTML entities, similar to GUMP::xss_clean();`
- urlencode `Encode url entities`
- htmlencode `Encode HTML entities`
- sanitize\_email `Remove illegal characters from email addresses`
- sanitize\_numbers `Remove any non-numeric characters`
- trim `Remove spaces from the beginning or end of strings`
- base64\_encode `Base64 encode the input`
- base64\_decode `Base64 decode the input`
- sha1 `Encrypt the input with the secure sha1 algorithm`
- md5 `MD5 encode the input`
- noise\_words `Remove noise words from string`
- json\_encode `Create a json representation of the input`
- json\_decode `Decode a json string`
- rmpunctuation `Remove all known puncutation characters from a string`
- basic\_tags `Remove all layout orientated HTML tags from text. Leaving only basic tags`

Creating your own validators and filters
========================================

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

Simply create your own class that extends the GUMP class.

```

require("gump.class.php");

class MyClass extends GUMP
{
	public function filter_myfilter($value)
	{
		...
	}

	public function validate_myvalidator($field, $input, $param = NULL)
	{
		...
	}

} // EOC

$validator = new MyClass();

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

Remember to create a public methods with the correct parameter types and counts.

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

Running the examples:
---------------------

[](#running-the-examples)

1. Open up your terminal
2. cd \[GUMP DIRECTORY/examples\]
3. php \[file\].php

The output will depend on the input data.

TODO
====

[](#todo)

- Add composer compatibility
- A currency validator
- An address validator
- A country validator
- Location co-ordinates validator
- HTML validator
- Language validation ... determine if a piece of text is a specified language
- Validate a spam domain or IP.
- Validate a spam email address
- Validate spam text with askimet or something similar
- Improve documentation
- More examples
- W3C validation filter?
- A filter that integrates with an HTML tidy service?:
- Add a twitter &amp; facebook profile url validator:
- Add more logical examples - log in form, profile update form, blog post form, etc etc.

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.1% 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://avatars.githubusercontent.com/u/71701357?v=4)[deftx](/maintainers/deftx)[@deftx](https://github.com/deftx)

---

Top Contributors

[![sn](https://avatars.githubusercontent.com/u/77145?v=4)](https://github.com/sn "sn (77 commits)")[![rcrowe](https://avatars.githubusercontent.com/u/282571?v=4)](https://github.com/rcrowe "rcrowe (2 commits)")[![rgr4y](https://avatars.githubusercontent.com/u/1844457?v=4)](https://github.com/rgr4y "rgr4y (2 commits)")

### Embed Badge

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

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

###  Alternatives

[chaoswey/taiwan-id-validator

台灣身分證、統一編號驗證

319.9k](/packages/chaoswey-taiwan-id-validator)

PHPackages © 2026

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