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.3) and ZERO dependencies!
Install with composer
Short format example for validations
Short format example for filtering
Long format example
:star: Available Validators
Important: If you use Pipe or Semicolon as parameter value, you must use array format.
| Rule | Description |
|--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **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 semicolons | Verify that a value is contained within the pre-defined value set. |
| **contains_list**,value1;value2 | Verify 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;value2 | Verify that a value is contained within the pre-defined value set. Error message will NOT show the list of possible values. |
| **boolean**,strict | Determine 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**,240 | Determine if the provided value length is less or equal to a specific value. |
| **min_len**,4 | Determine if the provided value length is more or equal to a specific value. |
| **exact_len**,5 | Determine if the provided value length matches a specific value. |
| **between_len**,3;11 | Determine 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 & 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/Y | Determine if the provided input is a valid date (ISO 8601) or specify a custom format (optional). |
| **min_age**,18 | Determine if the provided input meets age requirement (ISO 8601). Input should be a date (Y-m-d). |
| **max_numeric**,50 | Determine if the provided numeric value is lower or equal to a specific value. |
| **min_numeric**,1 | Determine if the provided numeric value is higher or equal to a specific value. |
| **starts**,Z | Determine if the provided value starts with param. |
| **required_file** | Determine if the file was successfully uploaded. |
| **extension**,png;jpg;gif | Check the uploaded file for extension. Doesn't check mime-type yet. |
| **equalsfield**,other_field_name | Determine 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**,1 | Check if an input is an array and if the size is more or equal to a specific value. |
| **valid_array_size_lesser**,1 | Check if an input is an array and if the size is less or equal to a specific value. |
| **valid_array_size_equal**,1 | Check if an input is an array and if the size is equal to a specific value. |
:star: Available Filters
Filter rules can also be any PHP native function (e.g.: trim).
| Filter | Description |
|------------------------|-----------------------------------------------------------------------------------------------------------------------|
| **noise_words** | Replace noise words in a string (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. ([“ ”] => ", [‘ ’] => ', [–] => -, […] => ...) |
| **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
Creating your own validators and filters
Adding custom validators and filters is made easy by using callback functions.
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_".
Global configuration
This configuration values allows you to change default rules delimiters (e.g.: required|contains,value1;value2
to required|contains:value1,value2
).