Download the PHP package forestry/form-validator without Composer
On this page you can find all versions of the php package forestry/form-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download forestry/form-validator
More information about forestry/form-validator
Files in forestry/form-validator
Package form-validator
Short Description Validation of form data using defined rulesets.
License MIT
Homepage https://github.com/ForestryCodes/form-validator
Informations about the package form-validator
Forestry Form validator
Library to validate form data based on rules.
Install
Via Composer
Usage
Create a validator
Define a ruleset for a form
Validate the form data
Show error message
You can also wrap error messages with custom markup:
Rules
This package comes with the following built-in rules:
Rule | Parameter | Description |
---|---|---|
alpha | none | Allows only text, space, . and - |
alphanum | none | Allows text and numerical values |
boolean | none | Checks if the value can be interpreted as a boolean true (true , 1 , yes or on ). |
date | format | Checks if the value is a valid date, time or date-time string. You can provide a date format to check against. |
none | Checks if the value is a valid email address. | |
float | none | Checks if the value is a valid float value. |
integer | none | Checks if the value is a valid integer value. |
ip | none | Checks if the value is a valid IP address. |
max | number | Checks if the value exceeds number characters. |
min | number | Checks if the value has at least number characters. |
natural | none | Checks if the value is a natural number. |
number | none | Checks if the value is a number. |
phone | none | Checks if the value is a valid phone number format. |
required | none | Checks if the value is set. |
same | fieldname | Compares if the value matches with the one in fieldname . |
url | none | Checks if the value is a valid URL. |
same
rule example
With this rule, you can define that two fields must have the same value, e.g. password fields:
Custom messages
Instead of using the default error messages, you can also pass a custom one with each rule:
Custom rules
You can define your own rules:
First, create a class which implements the Forestry\FormValidator\SimpleRuleInterface
or Forestry\FormValidator\ParameterRuleInterface
. The later on is used for rules whose have a parameter.
Next, register your rule with a name and the full qualified class name.
If you want to change an already registered rule, use the updateRule()
method.
Testing
Contributing
Please see CONTRIBUTING for details.
Credits
- daniel-melzer
- All Contributors
License
The MIT License (MIT). Please see License File for more information.