Download the PHP package hypnokizer/validator without Composer
On this page you can find all versions of the php package hypnokizer/validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hypnokizer/validator
More information about hypnokizer/validator
Files in hypnokizer/validator
Package validator
Short Description Class to validate a dataset
License MIT
Homepage https://github.com/Hypnokizer/Validator
Informations about the package validator
Validator Class
This is a simple validator class. It can be used without dependancies, but extends the database class. It is based on https://github.com/devwithkunal/php-validator-class.
Basic Use
Create the class instance. The constructor parameter is an associative data array to be validated containing key value pairs of field names and values. If the $data is not specified, the class attempts to pull in POST data, then GET data.
Run validation checks by chaining methods to the field() method. The field() method must start every method chain.
Check if the data is valid using the isValid() method.
Basic Methods
To start validation of a field, use the field() method. Once all validations are performed, use the isValid() method to determine if they were successful.
| Method | Description |
|---|---|
field($name, $alias) |
Set the field name to start validation.$name - Name of the field/key to validate.$alias - Alias to use in error messages instead of the field name. |
isValid() |
Check if all validations are successful. |
Validation methods available
After the field() method is called for a field, you can chain validation methods for each field.
| Method | Description |
|---|---|
alpha($ignore) |
Check for alphabetic characters. |
alphanumeric($ignore) |
Check for alphanumeric characters. |
changecase($case) |
Change case of string: capitalize, uppercase, lowercase. |
contains($chars) |
Check if the value contains specific characters. |
date() |
Check for a valid date. |
dateafter($date) |
Check if a date comes after the given date. |
datebefore($date) |
Check if a date comes before the given date. |
email() |
Check for email address. |
enum($list) |
Check if a value is in the list of approved values. |
equals($value) |
Check if value is equal to a given value. |
integer() |
Check for integer. |
length($length) |
Check for exact length of string. |
maxlength($length) |
Check for maximum length of string. |
maxvalue($value) |
Check for maximum value of integer or float. |
minlength($length) |
Check for minimum length of string. |
minvalue($value) |
Check for minimum value of integer or float. |
money($ignore) |
Check for currency. Changes string to decimal by removing dollar signs, commas, decimals, and negative signs. |
numeric() |
Check for numeric characters. |
period() |
Check for a date string and convert it to a period (Ex: Y-m-01). |
phone() |
Check for valid U.S. phone number. Removes non-numeric characters and confirms length of string. |
regex($pattern) |
Check against a regex pattern. |
required() |
Check if the required value exists. |
state() |
Check for valid U.S. state abbreviation. |
zip() |
Check for valid U.S. zip code. |