added docblock and readme docs for using the new filter

This commit is contained in:
Andrew Willis 2014-01-09 22:18:29 +00:00
parent 2d0790b984
commit 322df8b021
2 changed files with 43 additions and 0 deletions

View File

@ -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

View File

@ -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)
{
/**