84 Commits

Author SHA1 Message Date
notona
7c990e39ef fix integer validation process 2017-02-20 12:18:18 +09:00
Acho Arnold
f698be0c95 Makes the data parameter optional in the constructor
This Fixes #184
2017-02-14 16:30:25 +01:00
Willem Wollebrants
c8895683f7 mapFieldRules 2017-02-09 20:39:17 +01:00
Marcel Prince
a09ac827c6 Add boolean rule to README & remove unnecessary ternary 2017-01-24 16:07:48 -08:00
Ivan Palamarchuk
b0c188d430 Fix incorrect IDE work 2017-01-16 16:24:57 +03:00
Egor Gruzdev
5181664c79 for PhpStorm validation 2016-12-14 10:40:14 +02:00
Willem Wollebrants
f8290a8c59 Fix bug where Validator::withData would also erase all rules 2016-12-09 11:44:39 +01:00
Andy Snell
f9dd486b5d
Update MasterCard BIN Range
Updates the credit card validator regular expression for the MasterCard brand to also match 16-digit card numbers starting with 22 - 27.  Additionally, updates the unit test for credit cards with two published test cards in the new BIN range.

Additional information on the BIN range update can be found at: https://www.mastercard.us/en-us/issuers/get-support/2-series-bin-expansion.html
2016-12-05 00:09:39 -05:00
shin1x1
4f0f78ecfb Fix wrong @return 2016-11-15 18:06:16 +09:00
Matteo Kloiber
a6be7e2dd0 Validator::rule now accepts any kind of callback
This has been achieved by making sure that the rule is neither
a "native" Validator rule (e.g. there is a validate{$CamleCaseName}
method) nor it has been registered.

If both conditions are met, the rule (even if it is a string)
will be accepted and used.

Tests for this case have also been added.
2016-11-06 01:46:35 +01:00
Matteo Kloiber
74a882969e Indent fixed 2016-11-06 01:46:28 +01:00
Matteo Kloiber
7a5fd66990 Validator::rule now supports closures
Validator::rule now allows the rule to be a closure.
This allows us to add an anonymous rule that is only
valid for the specified field(s):

$someObject = new MyObject();
$v->rule(function($field, $value) use ($someObject)
    return $value === $someObject->someState();
}, ["shared_secret", "other"])
    ->label("invalid state!");

This is especially useful if you have either a) have
a rule which you are not likely to be reusing or b)
you need access to some object which cannot be easily
connstructed (because it requires IO access, etc).

Either way, this is really only convenience method
because it saves you a call to Validator::addInstanceRule.

Internally, it does exactly that: it 1) determines a valid
rule name, 2) calls addInstanceRule() with the name
determined in 1) and the Closure, and then 3) replaces
the $rule parameter (which is the Closure object) by
the name of the rule.

1) is determined like this: if multiple parameters were
given, they are joined together into one string glued
with a underscore. '_rule' is then appended so that
the name becomes all_params_rule. If the name is already
used by any other rule, it will append up to 5
pseudo-random digits to the rule. In the unlikely event
that this rule is also used, step 1) will be repeated
until a unique rule name is found.
2016-11-06 01:46:25 +01:00
Matteo Kloiber
df78fe188c Added support for instance rules
Instance rules are not shared among other validator
objects (thus they are not static). This is useful
if you have a rule you do not want your other validators
to use (because it is very special to this validator).

The parameter given to addInstanceRule is identically to
addRule:

    public function addInstanceRule(string $name, callable $callback [, string message])

Instead of appending to the static variables $_rules, and
$_ruleMessages, it now appends to $_instanceRules and
$_instanceRuleMessages.

A new getter for the rules and ruleMessage has also been added:

    public array getRules()
    public array getRuleMessages()

All existing code has been updated to use getRules(), and
getRuleMessages() instead of $_rules, and $_ruleMessages.
2016-11-06 01:46:17 +01:00
Willem Wollebrants
94317636d9 Added withData method for immutable reusability 2016-08-17 21:44:17 +02:00
misantron
d47c6206ed Change contains validator default mode to strict 2016-05-21 20:48:01 +03:00
misantron
a89c0972c1 Contains validator update, between validator added 2016-03-26 00:55:08 +03:00
Matthew Laver
0156bfc54e add acceptable accepted value
the string of '1' is also evaluated to true and a post variable is more likely to be set to a string
2016-03-11 10:31:07 +00:00
Willem Wollebrants
39eaf820c1 Change scope of checkAndSetLabel for easier extension 2016-02-22 13:31:29 +01:00
Willem Wollebrants
4112b40452 Merge pull request #140 from MaJerle/master
Added "optional" rule validation: with this rule if a value is provided it will be validated, even if it's an empty string
2016-02-22 13:21:35 +01:00
Chris Van Patten
3ee508987e Pass $this->_fields to callbacks defined in addRule 2016-01-05 09:48:23 -05:00
Tilen Majerle
0d77529c90 Added "optional" rule validation
With 'optional' rule validation, values does not need to be included in data array.
However, if they are, they must pass validation.

Before this patch, if you pass data with empty ( '' ) value, then it is ignored if "required" was not added.
With this version, this is now fixed.

Text case available here: http://pastebin.com/N2eQjJys
2015-11-30 22:23:21 +01:00
USAMI Kenta
96221ea4d3 Add type check for between comparison
Return 0 if $value is not numeric value
2015-11-20 16:57:15 +09:00
USAMI Kenta
28254e76c2 Add type check for stringLength
Return 0 if $value is not string
2015-11-20 16:55:56 +09:00
Alexandros Diamantidis
919005c0f8 Fix validateUrlActive() to check host part of URL for correct DNS records
validateUrlActive() calls checkdnsrr() which by default looks only for MX records, and passes the whole tail part of the URL after the prefix. It should isolate the host and check for A, AAAA or CNAME DNS records.
2015-09-17 13:32:20 +03:00
Vance Lucas
c7342e025a Fix #115 strict flag for in_array 2014-11-20 09:24:40 -06:00
cguroo
eb12058860 Update Validator.php
Hi, I have added a strict flag as an argument since anyone who wishes a strict comparison shall have the option, and btw in_array without strict is sort of "useless" in most cases, IMHO.

heres why i say so.
http://php.net/manual/en/function.in-array.php#106319
2014-11-19 12:09:20 +05:30
Lane Roberts
f8f1c0061b Fix 'Illegal offset type in isset or empty' warning when a param is an object.
Params can be any data type, but keys can only be integers or strings.
2014-09-18 11:08:28 -05:00
Mark Cahill
eace42656a Validate an array of discrete values 2014-09-08 12:34:46 -04:00
Vance Lucas
6d78b00334 PSR-2 formatting and small updates 2014-09-08 11:10:41 -05:00
Mark Cahill
c197b10891 Validation of nested arrays, closes #8 2014-09-08 10:40:53 -04:00
ecoreng
bd09c30efc refactor to avoid foreach when filtering 2014-07-31 22:55:20 -07:00
Vance Lucas
6d36b12f76 Merge pull request #85 from Typeform/master
Add instanceOf to rules in readme.md
2014-07-29 13:00:00 -05:00
Victor Bjelkholm
9d90b08813 Show instance name in instanceOf error message 2014-07-29 16:39:14 +02:00
Justin Hook
9b5b0cff77 Fixes #64. Updated validateDateFormat to use warning_count for validation check 2014-07-26 15:47:50 +01:00
Victor Bjelkholm
8aa6ad1c5d Allow date to be DateTime object 2014-07-14 14:02:34 +02:00
Victor Bjelkholm
ad0f6b9708 Add instanceOf validation 2014-07-14 12:43:00 +02:00
Vance Lucas
f52df87b56 Made the BC Math extension optional 2014-07-07 09:00:28 -05:00
Rayne
40f4e5b34b Typo in Validator 2014-06-10 20:25:58 +02:00
Vance Lucas
ad89c5ec35 Merge pull request #72 from thinkjson/validate-zero
Run validation is field is non-null instead of truthy. Fixes #70
2014-05-27 14:51:00 -05:00
Mark Cahill
272fe84b15 Run validation is field is non-null instead of truthy. Fixes #70 2014-05-27 15:31:13 -04:00
Vance Lucas
2d111d9204 Merge pull request #67 from brandonlamb/features/phpdoc
Update docblocks, consistency/missing types, etc
2014-05-27 14:04:08 -05:00
Brandon Lamb
6454f648a5 Apply some PSR formatting updates 2014-05-26 13:55:30 -07:00
Brandon Lamb
37563d76ba Add missing throws phpdoc 2014-05-26 13:39:03 -07:00
Brandon Lamb
57f2476642 Update docblocks, consistency/missing types, etc 2014-05-26 13:37:13 -07:00
Vance Lucas
430a8324ec Merge pull request #53 from Kilte/feature-length
Add min/max-length validators
2014-04-10 10:53:37 -05:00
Justin Hook
631a5e2138 Updated min and max rules to use bccomp for number comparison. 2014-04-02 21:58:30 +01:00
Justin Hook
4fb6f478ef Fixed issue with Min/Max rules using decimals 2014-04-01 21:17:00 +01:00
Kilte
8871f81476 Add min/max-length validators 2014-01-25 21:18:42 +04:00
Vance Lucas
e011ab81c4 Merge pull request #25 from neves/fix-addRule
Fix add rule
2014-01-11 19:48:40 -08:00
Andrew Willis
f26a1f55b4 fixed indentation and php5.3 array syntax 2014-01-10 06:54:10 +00:00