Download the PHP package originphp/validation without Composer
On this page you can find all versions of the php package originphp/validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download originphp/validation
More information about originphp/validation
Files in originphp/validation
Package validation
Short Description OriginPHP Validation
License MIT
Homepage https://www.originphp.com
Informations about the package validation
Validation
This provides a Validation
library and the Validator
class for setting up and running validation rules on arrays of data.
Installation
To install this package
Validation Library
For example
The full list of validation rules are listed below, after the next section.
Validator
To validate an array of values
Rule options:
- rule: name of rule, array, callbable e.g. required, numeric, ['date', 'Y-m-d'],[$this,'method']
- message: the error message to show if the rule fails, if not supplied a default one will be used.
- on: default:null. set to create or update to run the rule only on those, works with second argument of
validate
- allowEmpty: default:false validation will be pass on empty values
- stopOnFail: default:false wether to continue if validation fails
You can also use custom validation rules using
Or to use a closure
The Validator
uses the Validation
rules and has 3 additional validation rules built in, required
, optional
, and present
.
These rules should be called first, and for required
and present
, if they fail no further validation rules will run.
- required: this means the key must be
present
and the value isnotEmpty
- optional: this means that data is optional, if the value is
empty
then it will not run any more validation rules. - present: this means that the data array must have the key present, its irrelevant if the value is empty or not.
ValidateTrait
You can add validation any Plain Old PHP Object.
Then you can check its valid
You can
Validation Rules
accepted
Validates a value is accepted (checkbox is checked)
after
Validates a date is after a certain date, dates are passed to the strtotime
function.
alpha
Validates a string only contains alphabetic characters from the default locale
alphaNumeric
Validates a string only contains alphanumeric characters from the default locale
array
Validates a value is an array
before
Validates a date is before a certain date, dates are passed to the strtotime
function.
boolean
Validates a value is a boolean type
creditCard
Validates a credit card number
All regex rules written from scratch using current IIN ranges, so whilst they are accurate the rules are not mature yet.
date
Validates a date using a format compatible with the PHP DateTime
class.
dateFormat
Validates a date using a format compatible with the PHP DateTime
class, this is used by Validation::date
, Validation::time
, and Validation::dateTime
.
The format, which is the second argument is required
dateTime
Validates a datetime using a format compatible with the PHP DateTime class.
decimal
Validates a value is a float. Alias for float
Validation for an email address
You can also check that the email address has valid MX records using the getmxrr
function.
equalTo
Validates a value is equal to another value, only values are compared.
extension
Validates a value has an extension. If an array is supplied it will look
You can also check a file that has been uploaded with the correct extension.
float
Validates a value is a float.
fqdn
Validates a string is Fully Qualified Domain Name (FQDN).
You can also check the DNS records using checkdnsrr
to ensure that is really valid and not just looks like its valid.
greaterThan
Validates a value is greater than
greaterThanOrEqual
Validates a value is greater than or equals a value.
hex
Validates a hexadecimal string.
hexColor
Validates a value is a hex color
iban
Validates a value is an IBAN number
in
Validates a value is in a list
integer
Validates a value is an integer
ip
Validates a value is an IP Address, by default it validates as either IPV4 or IPV6.
To validate only IPV4 or IPV6
ipRange
Validates an IP address is in a range.
json
Validates a value is a JSON string.
length
Validates a string has a certain length.
lessThan
Validates a value is less than another a value.
lessThanOrEqual
Validates a value is less than or equal to another a value.
lowercase
Validates a string is in lowercase.
luan
Validates a number using the LUAN algoritm.
macAddress
Validates a string is a valid mac address.
maxLength
Validates a string has a maximum length.
md5
Validates a string is a MD5 hash.
You can also allow it to be case insensitive
mimeType
Validates a file has a particular mime type.
minLength
Validates a string has a minimum length.
notBlank
Validates a value is not empty and has anything other than whitespaces.
notEmpty
Validates a value is not empty, a value is empty
null
- empty string
''
- an empty array
- empty file upload
notIn
Validates a value is not in an array of values.
numeric
Validates a value is an integer or a float.
present
Validates an array has a key.
range
Validates a number or float is within a range.
regex
Validates a string using a REGEX pattern.
string
Validates that a value is a string
time
Validates a string is a time.
upload
Validates a file upload was successful.
You can also allow optional file upload, meaning if no file is upload then it will return true if there was no error uploading it.
uppercase
Validates a string is uppercase.
url
Validates a string is an URL.
uuid
Validates a string is a UUID
You can also allow uppercase