114 Commits

Author SHA1 Message Date
peterkinamo
e5ae2c9a5f ipv4 and ipv6 rule and tests added 2018-08-03 13:02:21 +02:00
peterkinamo
971da213a3 Ascii rule added
Ascii unit test added
2018-08-03 12:28:23 +02:00
Willem Wollebrants
fcaa1d5d52 make phpdoc more specific for parameter in Validator::addInstanceRule and Validator::addRule, both need a callable 2018-06-25 22:18:19 +02:00
Willem Wollebrants
3908f086e0 fix incorrect phpdoc for callable 2018-06-25 22:15:31 +02:00
Willem Wollebrants
b6589e85ea
Strict integer rule
Fixed strict integer rule and added more integer unit tests
2018-03-29 20:57:51 +02:00
Julius Ijie
4103c8bd40 Forced stopOnFirstFail parameter to bool 2018-02-23 15:59:30 +01:00
Julius Ijie
8636fed8f5 Removed boolean type declaration only available on PHP7 2018-02-23 15:55:45 +01:00
Julius Ijie
6837c9dfab Added option to stop validation when a rule is failed 2018-02-23 15:25:35 +01:00
Willem Wollebrants
013672dfce
Merge pull request #231 from piotr-cz/patch-1
Fix typo in docblock
2018-02-10 14:08:48 +01:00
Willem Wollebrants
8abb9b7220
Merge pull request #237 from mangopeaches/nested-equals-different
added nested array support for validateEquals and validateDifferent
2018-02-07 17:35:13 +01:00
Tom Breese
7c94b2ae5a added support for nested arrays in validateEquals and validateDifferent validation methods 2018-02-04 13:24:47 -05:00
Jabari
8603b2bec3 Added idn_to_ascii() with a check to make sure the function itself exists as well as a check for a required constant that it needs to function. 2018-01-05 22:28:47 -06:00
Jabari Hunt
28ef275cde Restored the original validateEmail() method. Created a new method called validateEmailDNS() that validates both the email address itself (using the ValidateEmail() method) as well as the domain name in the email address. 2018-01-01 15:11:21 -06:00
Jabari Hunt
55154359dc Fixed a typo that was introduces in an unrelated comment. 2017-12-13 16:06:31 -06:00
Jabari Hunt
255384baa8 Made the domain check an option (via third method param). 2017-12-13 14:52:24 -06:00
Jabari Hunt
ae7716c900 Improved the email validator by making sure the domain name is valid. 2017-12-13 12:30:45 -06:00
Piotr
2438da6a99
Fix typo in docblock 2017-12-08 16:00:16 +01:00
Willem Wollebrants
9726d0f835 remove unused parameter for required rule 2017-10-30 19:44:17 +01:00
Dennis Meckel
eb436a382f Fixed strict integer rule and added more integer unit tests 2017-10-13 19:39:59 +02:00
Willem Wollebrants
4cc030c68a validate fields that are required, but may have empty or null values. #208 2017-08-28 21:52:21 +02:00
Juan Antonio Tubio
a80cbf0f3f Fixing code indentation 2017-07-18 16:46:38 +02:00
Juan Antonio Tubio
c6b2865ef6 Checking if mb_strpos() exists before use them 2017-07-18 16:44:05 +02:00
Juan Antonio Tubio
51575f3f9d Don't add {field} to message uf already exists
Fixed rule() function to don't add {field} to message if already exists on them
2017-07-18 16:18:00 +02:00
Willem Wollebrants
86cdecf193 Always run 'accepted' validation (#101) 2017-07-06 11:21:27 +02:00
Willem Wollebrants
ec77d601ad Handle malformed bulk rules (#204) 2017-07-06 11:03:04 +02:00
Willem Wollebrants
a6cf3a8c86 Merge pull request #201 from auroraeosrose/foreachbug
Check if the value in getParts is non-scalar to prevent "Invalid argument to foreach" error
2017-06-23 23:38:17 +02:00
Elizabeth M Smith
a7e89cf26c fix it correctly... 2017-06-23 14:41:46 -04:00
Elizabeth M Smith
e8ab4dc157 Fixes invalid argument to foreach
happens when you have a rule looking for sub items in arrays, but actually pass in a scalar value
bombs out with invalid argument to foreach
2017-06-23 14:01:34 -04:00
Elizabeth M Smith
c729a0c4ac avoids php blowing up if an array value is passed
if incoming data has an array value set with a slug rule on it, you get 
preg_match() expects parameter 2 to be string, array given
vendor\vlucas\valitron\src\Valitron\Validator.php:571
2017-06-23 13:41:39 -04:00
Willem Wollebrants
28d954817b Use an optional parameter to make validateInteger more strict 2017-02-21 21:11:14 +01:00
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