- 100% free & Open Source
- Super fluent API
- Loaded with built-in rules
- Easy to extend
- Unit Tested
- Works on most PHP versions
Built-in Rules
Change the dropdown to check the syntax with different rules
- Required
- Password
- Same
- File
- Alpha
- Alnum
- Length
- Min
- Max
- Number
- IP
- Boolean
- Array
Extend Envalid
You can extend envalid by registering your custom rules based on your business requirements
<?php
use azi\Arguments;
use azi\Rules\Contracts\RuleInterface;
class NationalId implements RuleInterface {
/**
* @param $field
* @param $value
* @param Arguments $args
* @return mixed
*/
public function validate( $field, $value, Arguments $args )
{
# validate national ID card number and return true or false
}
/**
* @return mixed
*/
public function message()
{
return '{field} must be a valid NIC number';
}
}
Once your custom rule is ready, register it with Envalid and start using it
<php
$validator = new azi/Envalid();
$validator->addRule('cnic', new NationalId());
// now the rule is registered with Envalid let's use it
$validator->validate($_POST, [
'national_id' => 'cnic'
]);