Download the PHP package grahamsutton/validator without Composer

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

The validator is a simple PHP validation library to remove the hassle of creating (often times) ugly validation logic and takes huge inspiration from Laravel's internal validation library.

This library is intended to be lightweight (no dependencies!) and easy-to-use.

Build Status

Requirements:

To install, run the following in your project root:

Available Rules

Two Ways to Use It

There are two ways to perform validations:

Chain Methods

You can chain validation methods together if you want to perform validations...

-or-

Pipe Format (preferred)

Use can use pipe formatting the same way you do in Laravel if you want to perform multiple validations on a field. This is the preferred method of performing validations and looks better most of the time.

Retrieving Errors

Retrieving errors is simple. When a validation fails to pass, it will be recorded into an array that can be retrieved from two different methods: getErrors or getAllErrors.

getErrors: array

This will return a flat associative array, where the key is the name of the failed field and the value is the first error detected.

Note: Notice how some values fail multiple validations, like name, but there is only error message per field.

getAllErrors: array

If you want to get all error messages recorded for a all fields, just use getAllErrors method. This will return the name of the failed fields as the keys and an array of error messages per failed field as the values.

Available Rules

required

Validates that value is not empty and the field is present.

or

Default error message: The {field_name} field is required.

max:int

Determines the max value or string length that a field can have.

If the value provided is an integer, the validation will compare that the provided integer is less than or equal to the specified int value.

If the value provided is a string, the validation will compare that the value's string length (determined by PHP's strlen function) is less than or equal to the specified int value.

or

Default error message: The {field_name} field must be less than or equal to {int} characters.

min:int

Determines the minimum value or string length that a field can have.

If the value provided is an integer, the validation will compare that the provided integer is greater than or equal to the specified int value.

If the value provided is a string, the validation will compare that the value's string length (determined by PHP's strlen function) is greater than or equal to the specified int value.

or

Default error message: The {field_name} field must be greater than or equal to {int} characters.

int

Determines that a value is an integer based on PHP's is_int function.

or

Default error message: The {field_name} field must be an integer.

float

Determines that a value is a float based on PHP's is_float function.

or

Default error message: The {field_name} field must be an float.

numeric

Determines that a value is numeric based on PHP's is_numeric function. The value can be a string, as long as it can be cast to a numerical value.

or

Default error message: The {field_name} field must be a numeric value.

email

Determines that a value is a valid email address.

or

Default error message: The {field_name} field must be a valid email.

boolean

Determines that a value is true, false, 0, 1, "0", or "1".

or

Default error message: The {field_name} field must be a boolean value.

accepted

Determines that a value is true, 1, "1", or "yes". This is useful for ensuring that people accept things like terms and conditions for your site. This validation will fail if provided a false value.

"yes" will be parsed to lowercase when provided, just in case you provide it capitalized.

or

Default error message: The {field_name} field must be accepted.

array

Determines that a value is an array. Internally, it uses PHP's is_array function to determine its truthiness. Empty arrays are considered valid. Add a required validation to disallow empty arrays.

or

Default error message: The {field_name} field must be an array.

date

Determines that a value can be parsed by PHP's strtotime function.

or

Default error message: The {field_name} field is not a valid date.

afterDate:string

Determines if a value is after the specified date. The string parameter can be any value that can be parsed by PHP's strtotime function.

or

Default error message: The {field_name} field value must be after {after_date} (yyyy-mm-dd hh:mm:ss).

beforeDate:string

Determines if a value is before the specified date. The string parameter can be any value that can be parsed by PHP's strtotime function.

or

Default error message: The {field_name} field value must be before {before_date} (yyyy-mm-dd hh:mm:ss).

License

Validator is licensed under the MIT License - see the LICENSE file for details.


All versions of validator with dependencies

PHP Build Version
Package Version
No informations.
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 grahamsutton/validator contains the following files

Loading the files please wait ....