Download the PHP package neuron-php/validation without Composer

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

CI codecov

Neuron-PHP Validation

Validators for common values (email, dates, phone numbers, images, passwords) plus a way to combine them. Each validator answers one question: isValid().

Installation

Requires PHP 8.4 or higher and neuron-php/data.

Validating a value

Every validator implements Neuron\Validation\IValidator.

Built-in validators extend Neuron\Validation\Base. Call isValid(); the class implements the check in validate().

Several checks on one value

Collection runs named validators against the same value. getViolations() returns the names of the checks that failed.

One check per field

Policy is a trait. addRule() stores a validator under a name, and isRuleValid() runs it. A rule's validator can be a single check or a Collection.

Validators

Class Accepts
IsArray An array
IsBase64 A base64 string. URL-safe (- and _) is accepted unless you pass false
IsBoolean A bool. Loose mode also accepts 0, 1, '0', '1', true, false, on, off, yes, and no
IsCurrency A number with at most two decimal places, such as 1, 1.01, or -1.01. No symbol and no thousands separator
IsDate A date string in a format. Default Y-m-d, so 2015-01-01
IsDateRange A Neuron\Data\Objects\DateRange whose start is before its end
IsDateTime A date and time string. Default Y-m-d H:i:s, so 2015-01-01 14:15:16
IsDateWithinRange A date string that matches the format and falls inside a DateRange, including the endpoints
IsEin An employer identification number, NN-NNNNNNN
IsEmail An email address
IsFloatingPoint A float, or a numeric string such as 3.14. An int is rejected
IsImage Base64 image bytes, or a data:image/...;base64,... URI. See below
IsInSet A value from a list. Comparison is strict unless you pass false
IsInteger An int. The string '1' is rejected
IsIpAddress An IPv4 or IPv6 address
IsJson A string of JSON. The JSON value null, and anything that is not a string, is rejected
IsName Letters, spaces, periods, and commas, such as Dr. Lee Jones, PHD
IsNotEmpty A value PHP treats as non-empty. 0, '0', false, null, '', and [] fail
IsNotNull Anything other than null
IsNumberWithinRange A number inside a NumericRange, including the endpoints
IsNumeric An int, a float, or a numeric string
IsNumericRange A NumericRange whose minimum is less than its maximum
IsObject An object
IsPassword A string that meets the length and character rules you pass in
IsPhoneNumber A US number ###-###-####, or an international number when you ask for one
IsPositive A number greater than or equal to zero
IsRegExPattern A string that matches the pattern you pass in
IsString A string
IsStringLength A string whose length is between the minimum and maximum, inclusive
IsTime A time string. Default g:i:s A, so 1:30:23 PM
IsUpc A 12-digit UPC with a valid check digit, such as 123456789012
IsUrl A URL, such as http://example.org
IsUuid A UUID, 8-4-4-4-12 hexadecimal. Case does not matter

Dates and times

IsDate, IsDateTime, and IsTime compare the value to itself after parsing, so the string has to already be in the format. Change the format with setFormat(). IsTime also has getFormat().

IsDateWithinRange uses the same date format (default Y-m-d) and requires the date to fall inside the range. DateRange stores its endpoints as Y-m-d.

IsDateRange checks the range object itself: start must be earlier than end.

Numbers

Strings, sets, and passwords

IsPassword requires a minimum length. Maximum length, uppercase, lowercase, a digit, and a special character are optional. The default special-character set is !@#$%^&*()_+-=[]{}|;:,.<>?. Pass specialChars to use a different set.

Phone numbers

The default type is IsPhoneNumber::US, which requires ###-###-####.

An international number starts with + and contains 7 to 15 digits. Single spaces may separate digits. setType() switches an existing validator.

Images and base64

IsBase64 rejects an empty string. Whitespace is ignored. URL-safe base64 is accepted by default; pass false to require + and /.

IsImage accepts raw base64 or a data URI. By default it allows JPEG, PNG, GIF, and WebP, and it checks the decoded bytes. SVG is rejected unless you opt in, because SVG can contain scripts.

The constructor arguments are the allowed MIME types, a maximum decoded size in bytes (null for no limit), whether to inspect the image bytes, and whether to allow SVG.

Booleans

Writing a validator

Extend Base and implement validate(), or implement IValidator directly. Either can be passed to Collection and Policy.

More Information

License

MIT License - see LICENSE file for details


All versions of validation with dependencies

PHP Build Version
Package Version
Requires ext-curl Version *
ext-json Version *
neuron-php/data Version 0.9.*
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 neuron-php/validation contains the following files

Loading the files please wait ...