Download the PHP package h2lsoft/validator without Composer

On this page you can find all versions of the php package h2lsoft/validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package validator

Validator

A fluent, chainable PHP data validator with built-in internationalization support.

Version

Requirements

Installation

Install via Composer:

Quick Start

Usage

Creating a validator

Defining rules

Chain rules fluently after selecting an input with input():

Checking results

Custom error messages

Every rule accepts an optional $message parameter:

Use [FIELD] placeholder to reference the field label:

Custom errors

Custom validation with callbacks

Use custom() for business logic that doesn't fit standard rules:

Available Rules

String / Value Rules

Rule Description Example
required($msg) Must be present and not empty ->required()
email($msg) Must be a valid email ->email()
mask($mask, $msg) Must match a mask (9=digit, a=letter, *=any) ->mask('99-aaa')
in($list, $msg) Value must be in the list ->in(['a', 'b', 'c'])
notIn($list, $msg) Value must not be in the list ->notIn(['x', 'y'])
integer($unsigned, $msg) Must be an integer ->integer()
float($unsigned, $msg) Must be a float ->float(false)
min($min, $msg) Value >= min (or array count) ->min(1)
max($max, $msg) Value <= max (or array count) ->max(100)
between($min, $max, $msg) Value between min and max ->between(1, 10)
length($len, $msg) Exact character length ->length(5)
minLength($len, $msg) Minimum character length ->minLength(3)
maxLength($len, $msg) Maximum character length ->maxLength(255)
equal($value, $msg) Must equal a given value ->equal('yes')
accepted($msg) Must be 'yes', 'YES' or 1 ->accepted()
boolean($msg) Must be a boolean-like value (true/false/1/0/yes/no) ->boolean()
password($min, $upper, $digit, $special, $msg) Password strength validation ->password(8, true, true, true)
url($flags, $msg) Must be a valid URL ->url()
alpha($exc, $latin, $min, $cap, $msg) Alphabetic only ->alpha(' -')
alphaNumeric($exc, $latin, $min, $cap, $msg) Alphanumeric only ->alphaNumeric('_')
date($format, $msg) Valid date ->date('d/m/Y')
datetime($format, $msg) Valid datetime ->datetime('d/m/Y H:i')
dateBefore($date, $format, $msg) Must be before a given date ->dateBefore('2025-12-31', 'Y-m-d')
dateAfter($date, $format, $msg) Must be after a given date ->dateAfter(date('Y-m-d'), 'Y-m-d')
time($format, $msg) Valid time ->time('H:i')
timezone($msg) Valid timezone identifier ->timezone()
country($msg) Valid ISO 3166-1 alpha-2 country code ->country()
language($msg) Valid ISO 639-1 language code ->language()
currency($msg) Valid ISO 4217 currency code ->currency()
iban($msg) Valid IBAN with MOD-97 checksum ->iban()
bic($msg) Valid BIC/SWIFT code (8 or 11 chars) ->bic()
uuid($msg) Valid UUID (RFC 4122, v1-v5) ->uuid()
macAddress($msg) Valid MAC address (colon or hyphen) ->macAddress()
cssColor($msg) Valid CSS color (hex, rgb, hsl, named) ->cssColor()
regex($pattern, $msg) Must match a regex ->regex('/^\d+$/', 'Digits only')
notRegex($pattern, $msg) Must not match a regex ->notRegex('/admin/i', 'Forbidden')
ip($flags, $msg) Valid IP address ->ip()
ipV4($msg) Valid IPv4 address ->ipV4()
ipV6($msg) Valid IPv6 address ->ipV6()
json($msg) Valid JSON string ->json()
jsonArray($msg) Valid JSON array ([...]) ->jsonArray()
jsonObject($msg) Valid JSON object ({...}) ->jsonObject()
sameAs($field, $msg) Must equal another field's value ->sameAs('password')
different($field, $msg) Must differ from another field's value ->different('old_password')
requiredIf($field, $value, $msg) Required only when another field matches ->requiredIf('type', 'pro')
csrfToken($token, $msg, $regenerate) CSRF token validation (auto-regenerates on failure by default) ->csrfToken()
custom($callback, $msg) Custom validation via callback ->custom(fn($v) => $v > 10, 'Too low')

Array Rules (checkboxes, multi-select)

Rule Description Example
multiple($msg) Must be an array ->multiple()
min($min, $msg) Minimum selections ->min(2)
max($max, $msg) Maximum selections ->max(5)
between($min, $max, $msg) Selections between min and max ->between(1, 3)

File Rules

Rule Description Example
fileRequired($msg) File must be uploaded ->fileRequired()
fileExtension($ext, $msg) Allowed extensions ->fileExtension(['jpg', 'png'])
fileMaxSize($size, $msg) Max file size (kb, mb, gb) ->fileMaxSize('2mb')
fileImage($ext) Must be an image ->fileImage()
fileMime($mimes, $msg) Allowed MIME types ->fileMime(['application/pdf'])
fileUploaded($msg) Must be a real upload ->fileUploaded()
fileImageWidth($w, $strict, $msg) Image width constraint ->fileImageWidth(800, true)
fileImageHeight($h, $strict, $msg) Image height constraint ->fileImageHeight(600, true)
fileImageBase64($ext, $create, $msg) Validate base64 image ->fileImageBase64('png')

Internationalization

Supported locales

Code Language
en English (default)
fr French
es Spanish
pt Portuguese
de German
it Italian

Setting the locale

Adding custom translations

Utility Methods

Method Description
setData(array $data) Replace the data to validate
inputGet($name, $default) Get a value from the data
inputSet($name, $value) Set a value in the data
inputGetAll() Get all data values
setInputNames(array $names) Set display labels for multiple fields
setInputName($name, $label) Set a display label for one field
hasErrors() Get the error count
toJson($flags) Get result as JSON (auto-sets Content-Type header)
reset() Reset errors and state for reuse with new data

Full Example

License

MIT. See full license.


All versions of validator with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-mbstring Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package h2lsoft/validator contains the following files

Loading the files please wait ...