Download the PHP package jakesutherland/nomad-validate without Composer
On this page you can find all versions of the php package jakesutherland/nomad-validate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jakesutherland/nomad-validate
More information about jakesutherland/nomad-validate
Files in jakesutherland/nomad-validate
Package nomad-validate
Short Description A WordPress PHP Composer Package that provides you with an easy way to validate data against a set of rules and generate error messages.
License MIT
Homepage https://jakesutherland.com
Informations about the package nomad-validate
Nomad Validate
A WordPress PHP Composer Package that provides you with an easy way to validate data against a set of rules and generate error messages.
Installation
You can install Nomad Validate in your project by using composer.
Dependencies
Nomad Validate depends on Nomad Helpers for various functions and utilities and needs to be installed in order to run.
If for some reason you didn't install Nomad Validate via Composer as a required package in your project, you will still need to run composer install
to install it's dependencies as they are not included in the repository.
Documentation
Nomad Validate has one simple function that you can use to validate data against a set of rules.
Example Usage
Each data item must have each of the following arguments: key
, label
, value
, and rules
.
You can optionally overwrite rule error messages through the error_messages
argument and specify the rule key and your custom message. You can see this in the terms
example below.
Available Rules
Each rule is added to the rules
argument individually for each piece of data.
Some rules contain arguments which let you further customize how the data is being compared and validated. To pass in an argument add a colon :
after your rule key and then provide your argument value (<rule>:<argument>
). You can see examples of rules with arguments below.
boolean
Usage: boolean
, boolean:strict
, boolean:truthy
, boolean:falsey
Description: Checks that the value is a boolean value (true
or false
). You can also have it check for "truthy" (true, 1, 'true', '1', 'yes', 'on', 'truthy') or "falsey" (false, 0, 'false', '0', 'no', 'off', 'falsey') values.
choices
Usage: choices:value1,value2,value3
Description: Checks that the value is one of the provided choices. Each choice is separated by a comma.
date
Usage: date:Y-m-d
Description: Checks that the value is a date in the specified format. See https://www.php.net/manual/en/datetime.format.php for DateTime format options.
email
Usage: email
Description: Checks that the value is a valid email address.
equals
Usage: equals:value
Description: Checks that the value equals the provided value.
letters
Usage: letters
Description: Checks that the value only contains letters.
matches
Usage: matches:my_field_key
Description: Checks that the value matches the value of the specified key.
maxlength
Usage: maxlength:20
Description: Checks that the value character length is less than or equal to the provided number.
max
Usage: max:2021
Description: Checks that the value is less than or equal to the provided number.
minlength
Usage: minlength:10
Description: Checks that the value character length is greater than or equal to the provided number.
min
Usage: min:1900
Description: Checks that the value is greater than or equal to the provided number.
numbers
Usage: numbers
Description: Checks that the value only contains numbers.
numeric
Usage: numeric
Description: Checks that the value is numeric.
regex
Usage: regex:/^([A-Za-z0-9_\-\.]*)$/
Description: Checks that the value matches the given regular expression.
required
Usage: required
Description: Checks that the value is not empty.
trim
Usage: trim
Description: This is a special rule and simply trims whitespace from the left and right of the value.
url
Usage: url
Description: Checks that the value is a valid URL.
Available Hooks
nomad/validate/{$key}
nomad/validate/{$key}/{$rule_key}/error_message
nomad/validate/error_messages
Changelog
v1.1.0
- Updated
Nomad_Validate
class filename to be prefixed withclass-
. - Updated
Nomad_Validate
to be afinal
class. - Updated rules
minnumber
tomin
andmaxnumber
tomax
. Both are still backwards compatible. - Updated verbiage for
choices
rule error message. - Updated dependency
Nomad Helpers
to the latest version (1.2.0). This introduced theregister_nomad_package()
function that is now being used to register the Nomad Validate package. - Fixed
choices
rule to not also treat the value as if its required.
v1.0.0
- Initial Release
License
The MIT License (MIT). Please see License File for more information.
Copyright
Copyright (c) 2021 Jake Sutherland