mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-30 23:01:52 +00:00
added docblock and readme docs for using the new filter
This commit is contained in:
parent
2d0790b984
commit
322df8b021
34
README.md
34
README.md
@ -109,6 +109,40 @@ V::lang('ar');
|
||||
* `dateBefore` - Field is a valid date and is before the given date
|
||||
* `dateAfter` - Field is a valid date and is after the given date
|
||||
* `contains` - Field is a string and contains the given string
|
||||
* `creditCard` - Field is a valid credit card number
|
||||
|
||||
## Credit Card Validation usage
|
||||
|
||||
Credit card validation currently allows you to validate a Visa `visa`,
|
||||
Mastercard `mastercard`, Dinersclub `dinersclub`, American Express `amex`
|
||||
or Discovery `discovery`
|
||||
|
||||
This will check the credit card against each card type
|
||||
```php
|
||||
$v->rule('creditCard', 'credit_card');
|
||||
```
|
||||
|
||||
To optionally filter card types, add the slug to an array as the next parameter:
|
||||
|
||||
```php
|
||||
$v->rule('creditCard', 'credit_card', ['visa', 'mastercard']);
|
||||
```
|
||||
|
||||
If you only want to validate one type of card, put it as a string:
|
||||
|
||||
```php
|
||||
$v->rule('creditCard', 'credit_card', 'visa');
|
||||
```
|
||||
|
||||
If the card type information is coming from the client, you might also want to
|
||||
still specify an array of valid card types:
|
||||
|
||||
```php
|
||||
$cardType = 'amex';
|
||||
$v->rule('creditCard', 'credit_card', $cardType, ['visa', 'mastercard']);
|
||||
$v->validate(); // false
|
||||
```
|
||||
|
||||
|
||||
## Adding Custom Validation Rules
|
||||
|
||||
|
||||
@ -472,6 +472,15 @@ class Validator
|
||||
return (is_bool($value)) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that a field contains a valid credit card
|
||||
* optionally filtered by an array
|
||||
*
|
||||
* @param string $field
|
||||
* @param string $value
|
||||
* @param array $params
|
||||
* @return bool
|
||||
*/
|
||||
protected function validateCreditCard($field, $value, $params)
|
||||
{
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user