Download the PHP package sandromiguel/verum-php without Composer
On this page you can find all versions of the php package sandromiguel/verum-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sandromiguel/verum-php
More information about sandromiguel/verum-php
Files in sandromiguel/verum-php
Package verum-php
Short Description Server-Side Form Validation Library for PHP
License MIT
Homepage https://github.com/SandroMiguel/verum-php
Informations about the package verum-php

Verum PHP
Verum PHP is a server-side validation library for PHP that allows you to validate arrays (with file support) with ease. It comes with custom error messages, rules, built-in translations, and zero dependencies.
Server-Side Validation Library for PHP
- Validate arrays (with file support)
- Custom error messages
- Custom rules
- Built-in translations
- Zero dependencies
Table of Contents
- Getting Started
- Usage
- Custom validations
- Available Rules
- Contributing
- Questions
- License
Getting Started
Installation
Install Verum PHP with Composer
Usage
Simple usage example
Validate a simple registration form (name, email and age)
Valid form example
Input:
Output:
Invalid form example
Input:
Output:
Use RuleEnum class
You can use the RuleEnum class to access all rule names.
Specify the fields label (naming inputs)
Output:
Specify field labels for each language
Output (pt-pt):
Specify the messages language
You can use some built-in translations:
'en'-> English (default)'nl-nl'-> Dutch'pt-pt'-> Portuguese-Portugal'pt-br'-> Portuguese-Brazil
Specify the messages language using the LangEnum class
Specify a custom error message
- Useful to override the default error message.
- Useful for localization.
Output example:
Specify a custom error message with placeholders
Output example:
Specify a custom error message for fields with and without a label
Output - Field with label:
Output - Field without label:
Specify multiple custom error messages at once
Specify multiple custom error messages at once for fields with and without a label
Handling Multi-Name Fields
With Verum PHP, you can handle multi-name fields more effectively. These are fields that include language identifiers or other variations in their names. For example, if you have fields like title.en, title.pt, description.en, and description.pt, you can specify rules for them using wildcards or by targeting specific fields.
Using Wildcards to Apply Rules to All Variants
You can define rules for all variants of a field using the * wildcard. For example:
Output example:
Validating Specific Variants
If you only want to validate a specific variant of a field, you can target it directly. For example, to validate only the English title and make titles in other languages optional:
Output example:
This allows you to apply rules more precisely, ensuring flexibility in how multi-name fields are handled based on your application's needs.
Custom validations
You can use your custom validations and inject the error message.
Available Rules
- alpha
- alpha_numeric
- between
- between_length
- boolean_value
- contains
- date
- equals
- file_max_size
- file_mime_type
- float_number
- image_max_height
- image_max_width
- image_min_height
- image_min_width
- integer
- ip
- ipv4
- ipv6
- max
- max_length
- min
- min_length
- numeric
- regex
- required
- slug
- url
alpha
Checks whether the value contains only alphabetic characters.
| Value | alpha | alpha + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:x: | :x: |
0 |
:x: | :x: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:x: | :x: |
1 |
:x: | :x: |
true |
:x: | :x: |
'text' |
:heavy_check_mark: | :heavy_check_mark: |
'text with spaces' |
:x: | :x: |
alpha_numeric
Checks whether the value contains only alphanumeric characters.
| Value | alpha_numeric | alpha_numeric + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:heavy_check_mark: | :heavy_check_mark: |
0 |
:heavy_check_mark: | :heavy_check_mark: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:x: | :x: |
1 |
:heavy_check_mark: | :heavy_check_mark: |
true |
:x: | :x: |
'text' |
:heavy_check_mark: | :heavy_check_mark: |
'text with spaces' |
:x: | :x: |
between
Checks whether the value is between two values.
| Value | between [1, 10] | between [1, 10] + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:x: | :x: |
0 |
:x: | :x: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:x: | :x: |
1 |
:heavy_check_mark: | :heavy_check_mark: |
true |
:x: | :x: |
'some text' |
:x: | :x: |
between_length
Checks whether the number of characters of the value is between min and max values.
| Value | between_length [5,25] | between_length [5,25] + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:x: | :x: |
0 |
:x: | :x: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:x: | :x: |
1 |
:x: | :x: |
12345 |
:heavy_check_mark: | :heavy_check_mark: |
true |
:x: | :x: |
'text' |
:x: | :x: |
'text with 23 characters' |
:heavy_check_mark: | :heavy_check_mark: |
boolean_value
Checks whether the value is a boolean value. Returns true for 1/0, '1'/'0', 'on'/'off', 'yes'/'no', true/false.
| Value | boolean_value | boolean_value + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:heavy_check_mark: | :heavy_check_mark: |
0 |
:heavy_check_mark: | :heavy_check_mark: |
false |
:heavy_check_mark: | :heavy_check_mark: |
[] |
:x: | :x: |
-1 |
:x: | :x: |
'1' |
:heavy_check_mark: | :heavy_check_mark: |
1 |
:heavy_check_mark: | :heavy_check_mark: |
true |
:heavy_check_mark: | :heavy_check_mark: |
'text' |
:x: | :x: |
'on' |
:heavy_check_mark: | :heavy_check_mark: |
'off' |
:heavy_check_mark: | :heavy_check_mark: |
'yes' |
:heavy_check_mark: | :heavy_check_mark: |
'no' |
:heavy_check_mark: | :heavy_check_mark: |
contains
Checks whether the value is in an array.
| Value | contains ['low','high'] | contains ['low','high'] + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:x: | :x: |
0 |
:x: | :x: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:x: | :x: |
1 |
:x: | :x: |
true |
:x: | :x: |
'text' |
:x: | :x: |
'low' |
:heavy_check_mark: | :heavy_check_mark: |
'high' |
:heavy_check_mark: | :heavy_check_mark: |
date
Checks whether the value is a valid date (Y-m-d) or a custom format.
Default format (Y-m-d)
Custom format (e.g. d.m.Y)
| Value | date [Y-m-d] | date [Y-m-d] + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:x: | :x: |
0 |
:x: | :x: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:x: | :x: |
1 |
:x: | :x: |
true |
:x: | :x: |
'text' |
:x: | :x: |
'2020-09-30' |
:heavy_check_mark: | :heavy_check_mark: |
Checks whether the value has a valid email format.
| Value | email + required | |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:x: | :x: |
0 |
:x: | :x: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:x: | :x: |
1 |
:x: | :x: |
true |
:x: | :x: |
'text' |
:x: | :x: |
'[email protected]' |
:heavy_check_mark: | :heavy_check_mark: |
equals
Checks whether the value is equal to another.
Comparison with 'text'
| Value | equals | equals + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:x: | :x: |
0 |
:x: | :x: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:x: | :x: |
1 |
:x: | :x: |
true |
:x: | :x: |
'text' |
:heavy_check_mark: | :heavy_check_mark: |
'another text' |
:x: | :x: |
file_max_size
Checks whether the file size does not exceed a given value.
Enter a value in bytes.
Comparison with 102400 bytes
| Value | file_max_size | file_max_size + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
50000 |
:heavy_check_mark: | :heavy_check_mark: |
150000 |
:x: | :x: |
file_mime_type
Checks whether the file type is allowed.
| Value | file_mime_type | file_mime_type + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
image/png |
:heavy_check_mark: | :heavy_check_mark: |
text/plain |
:x: | :x: |
float_number
Checks whether the value is a floating point number.
| Value | float_number | float_number + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:x: | :x: |
0 |
:x: | :x: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:x: | :x: |
1 |
:x: | :x: |
12345 |
:x: | :x: |
123.45 |
:heavy_check_mark: | :heavy_check_mark: |
true |
:x: | :x: |
'text' |
:x: | :x: |
'text with spaces' |
:x: | :x: |
image_max_height
Checks whether the image height does not exceed a given value.
| Value | image_max_height | image_max_height + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
| 500px | :heavy_check_mark: | :heavy_check_mark: |
| 1000px | :x: | :x: |
image_max_width
Checks whether the image width does not exceed a given value.
| Value | image_max_width | image_max_width + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
| 500px | :heavy_check_mark: | :heavy_check_mark: |
| 1500px | :x: | :x: |
image_min_height
Checks whether the image height is not less than a given value.
| Value | image_min_height | image_min_height + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
| 100px | :x: | :x: |
| 500px | :heavy_check_mark: | :heavy_check_mark: |
image_min_width
Checks whether the image width is not less than a given value.
| Value | image_min_width | image_min_width + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
| 400px | :x: | :x: |
| 600px | :heavy_check_mark: | :heavy_check_mark: |
integer
Checks whether the value is integer.
| Value | numeric | numeric + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:x: | :x: |
0 |
:heavy_check_mark: | :heavy_check_mark: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:heavy_check_mark: | :heavy_check_mark: |
1 |
:heavy_check_mark: | :heavy_check_mark: |
true |
:x: | :x: |
'text' |
:x: | :x: |
ip
Checks whether the value is a valid IP address.
| Value | ip | ip + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:x: | :x: |
0 |
:x: | :x: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:x: | :x: |
1 |
:x: | :x: |
true |
:x: | :x: |
'text' |
:x: | :x: |
'10.10.10.10' |
:heavy_check_mark: | :heavy_check_mark: |
'2607:f0d0:1002:51::4' |
:heavy_check_mark: | :heavy_check_mark: |
ipv4
Checks whether the value is a valid IPv4 address.
| Value | ipv4 | ipv4 + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:x: | :x: |
0 |
:x: | :x: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:x: | :x: |
1 |
:x: | :x: |
true |
:x: | :x: |
'text' |
:x: | :x: |
'10.10.10.10' |
:heavy_check_mark: | :heavy_check_mark: |
'2607:f0d0:1002:51::4' |
:x: | :x: |
ipv6
Checks whether the value is a valid IPv6 address.
| Value | ipv6 | ipv6 + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:x: | :x: |
0 |
:x: | :x: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:x: | :x: |
1 |
:x: | :x: |
true |
:x: | :x: |
'text' |
:x: | :x: |
'10.10.10.10' |
:x: | :x: |
'2607:f0d0:1002:51::4' |
:heavy_check_mark: | :heavy_check_mark: |
max
Checks whether the value does not exceed a given value.
| Value | max | max + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:heavy_check_mark: | :heavy_check_mark: |
0 |
:heavy_check_mark: | :heavy_check_mark: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:heavy_check_mark: | :heavy_check_mark: |
1 |
:heavy_check_mark: | :heavy_check_mark: |
true |
:x: | :x: |
'text' |
:x: | :x: |
12345 |
:x: | :x: |
'12345' |
:x: | :x: |
max_length
Checks whether the number of characters of the value does not exceed a given value.
| Value | max_length | max_length + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:heavy_check_mark: | :heavy_check_mark: |
0 |
:heavy_check_mark: | :heavy_check_mark: |
false |
:heavy_check_mark: | :heavy_check_mark: |
[] |
:x: | :x: |
-1 |
:heavy_check_mark: | :heavy_check_mark: |
1 |
:heavy_check_mark: | :heavy_check_mark: |
true |
:heavy_check_mark: | :heavy_check_mark: |
'text' |
:x: | :x: |
12345 |
:x: | :x: |
'12345' |
:x: | :x: |
min
Checks whether the value is not less than a given value.
| Value | min | min + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:x: | :x: |
0 |
:x: | :x: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:x: | :x: |
1 |
:x: | :x: |
true |
:x: | :x: |
'text' |
:x: | :x: |
12345 |
:heavy_check_mark: | :heavy_check_mark: |
'12345' |
:heavy_check_mark: | :heavy_check_mark: |
min_length
Checks whether the number of characters of the value is not less than a given value.
| Value | max_length | max_length + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:x: | :x: |
'0' |
:x: | :x: |
0 |
:x: | :x: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:heavy_check_mark: | :heavy_check_mark: |
1 |
:x: | :x: |
true |
:x: | :x: |
'text' |
:heavy_check_mark: | :heavy_check_mark: |
12345 |
:heavy_check_mark: | :heavy_check_mark: |
'12345' |
:heavy_check_mark: | :heavy_check_mark: |
numeric
Checks whether the value is numeric.
| Value | numeric | numeric + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:heavy_check_mark: | :heavy_check_mark: |
0 |
:heavy_check_mark: | :heavy_check_mark: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:heavy_check_mark: | :heavy_check_mark: |
1 |
:heavy_check_mark: | :heavy_check_mark: |
true |
:x: | :x: |
'text' |
:x: | :x: |
regex
Checks whether the value matches a given regular expression.
Validation with the '/\/client\/[0-9a-f]+$/' pattern
| Value | regex | regex + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:x: | :x: |
0 |
:x: | :x: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:x: | :x: |
1 |
:x: | :x: |
true |
:x: | :x: |
'text' |
:x: | :x: |
'/client/77c9e105d1f548b29958f0512967de87' |
:heavy_check_mark: | :heavy_check_mark: |
'/client/invalid-uuid' |
:x: | :x: |
required
Checks whether the value is not empty.
| Value | required |
|---|---|
null |
:x: |
'' |
:x: |
'0' |
:heavy_check_mark: |
0 |
:heavy_check_mark: |
false |
:heavy_check_mark: |
[] |
:x: |
-1 |
:heavy_check_mark: |
1 |
:heavy_check_mark: |
true |
:heavy_check_mark: |
'some text' |
:heavy_check_mark: |
slug
Checks whether the value is a valid Slug (e.g. hello-world_123).
| Value | slug | slug + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:x: | :x: |
0 |
:x: | :x: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:x: | :x: |
1 |
:x: | :x: |
true |
:x: | :x: |
'text' |
:heavy_check_mark: | :heavy_check_mark: |
'text with spaces' |
:x: | :x: |
'hello-world_123' |
:heavy_check_mark: | :heavy_check_mark: |
url
Checks whether the value is a valid URL.
| Value | url | url + required |
|---|---|---|
null |
:heavy_check_mark: | :x: |
'' |
:heavy_check_mark: | :x: |
'0' |
:x: | :x: |
0 |
:x: | :x: |
false |
:x: | :x: |
[] |
:x: | :x: |
-1 |
:x: | :x: |
1 |
:x: | :x: |
true |
:x: | :x: |
'text' |
:x: | :x: |
'http://www.some-domain.com' |
:heavy_check_mark: | :heavy_check_mark: |
Contributing
Want to contribute? All contributions are welcome. Read the contributing guide.
Questions
If you have questions tweet me at @sandro_m_m or open an issue.
License
This project is licensed under the MIT License - see the LICENSE file for details
~ sharing is caring ~