Download the PHP package initphp/validation without Composer

On this page you can find all versions of the php package initphp/validation. 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 validation

InitPHP Validation

Fast, dependency-free data validation for PHP. Describe what each field should look like with a small rule DSL ("required|integer|range(1...10)"), callbacks, or custom named rules, and get back localized error messages.

CI Latest Stable Version Total Downloads License PHP Version Require

Requirements

Installation

Quick start

How it works

  1. Give it data. Pass an associative array to the constructor, or use setData() / mergeData().
  2. Queue rules. Each rule() call adds checks for one or more fields.
  3. Validate. validation() runs every queued rule, returns true when nothing failed, and consumes the queued rules — so the usual flow is queue → validate → read errors, repeated as needed.
  4. Read errors. getError() returns the messages from the most recent run.

Rules

A rule string is a pipe-separated list. Arguments go in parentheses and are comma-separated; arguments are trimmed, so only(a, b, c) and only(a,b,c) are equivalent. Rule names are matched case-insensitively.

Rule Description
required The value is present and not a blank string (numbers and non-empty arrays pass).
optional Pseudo-rule. If the field is absent, its other rules are skipped instead of failing.
empty The value is empty once trimmed.
integer An integer or an integer-looking string.
float A float/int or a float-looking string.
numeric A numeric value.
string A string.
boolean A real boolean or one of true, false, 1, 0.
array An array.
alpha Letters only (Unicode-aware).
alphanum / alphanumeric Letters and digits only.
mail A valid e-mail address.
mailHost(host, ...) A valid e-mail at one of the given hosts.
url A valid URL.
urlHost(domain, ...) A URL whose host equals, or is a subdomain of, one of the domains.
ip / ipv4 / ipv6 A valid IP address of the given family.
min(n) Numbers >= n; for strings/arrays the length/count >= n.
max(n) Numbers <= n; for strings/arrays the length/count <= n.
range(min...max) A number within the range. Also accepts min-max, ...max, min....
length(min...max) String length / array count within range. A single number is the maximum; open bounds (...max, min...) are allowed.
regex(name\|body) Matches a named pattern or an inline regex body.
date A DateTimeInterface, or any string strtotime() understands.
dateFormat(format) A date string in the given date() format, e.g. dateFormat(Y/m/d).
again(field) Loosely equals the value of another field.
equals(value) Loosely equals the given value.
startWith(value) A string starting with the value, or an array whose first element equals it.
endWith(value) A string ending with the value, or an array whose last element equals it.
in(needle) Case-insensitive substring (strings) or strict membership (arrays).
notIn(needle) The inverse of in.
contains(needle) Case-sensitive substring.
notContains(needle) The inverse of contains.
only(a, b, ...) Case-insensitively equals one of the options.
strictOnly(a, b, ...) Case-sensitively equals one of the options.
creditCard(type?) A credit card number. Optional type: amex, visa, mastercard, maestro, jcb, solo, switch.

See docs/rules-reference.md for a per-rule reference with examples.

Callable rules

Pass a callback as the rule. It receives the field value and returns a boolean. The third argument to rule() is a custom message.

You can also mix strings and callbacks in one array:

Custom named rules

Register reusable rules with extend() so they work inside the DSL string, arguments and all:

Optional fields

optional skips a field's rules when it has no value, but still validates it when present:

Named patterns

The regex rule can reference a named pattern. Built-in names include uri, slug, url, alpha, words, alphanum, int, float, tel, text, file, folder, address, date_dmy, date_ymd and email. Register your own with pattern():

Error messages and localization

Messages support {field} and positional placeholders: {1} is the value and {2} is the first rule argument.

Replace raw field names with friendly labels:

Switch language (the package ships with en and tr), or override individual messages:

Point at your own language directory with setLocaleDir(). See docs/localization-and-messages.md.

Exceptions

Everything thrown by the package implements InitPHP\Validation\Exception\ExceptionInterface:

Upgrading from 1.x

Version 2.0 is a breaking release. The headline changes:

Full notes: docs/upgrading-from-1.x.md.

Testing

Contributing

Contributions are welcome. Please read the org-wide Contributing guide and open a pull request against main. New behaviour should come with tests, and composer ci should pass.

Credits

License

Released under the MIT License. Copyright © 2022 InitPHP.


All versions of validation with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
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 initphp/validation contains the following files

Loading the files please wait ...