06-20-2017, 01:18 PM
Somehow my topic disappeared while I was editing so I'm reposting it.
https://pastebin.com/KmhvbPFh
46,51 - Replaced empty() with strlen()==0 because if the input was "0" (number zero) then the validation wouldn't work.
78-87 - Optionally you can pass array to the unique for a more complicated query (provided you have this patch). For example:
Also it will fail validation if query returned an error (which the original did not do).
110-147 - Added rules <, >, <=, >=, !=, == for comparing numbers. They will automatically check if value is a number so there's no need to stack it with is_numeric. For example: (equal to 25 or greater ). You can also compare it against other fields. For example: (greater than the number in the "Price" input)
149-152 - Added rule is_int for excluding floats.
209-210 - In function addError() added condition to prevent error message duplication.
===
EDIT:
54-55, 62-63, 70-73 - One issue with using array keys as rules is that you can't stack them. I've added an option to pass an array to rules: min, max, matches, <, >, <=, >=, !=, ==. For example:
154-158 - Added rule is_timezone for verifying time zone name.
100, 149 - Added (synonymous with ). Added (synonymous with )
160-189 - Added rule in for matching string lowercase.
30, 38-41 - If value is an array then will return an error. Because I use I don't want to sanitize again so I added optional argument to skip it
43-44, 51, 57, 65 - My earlier change to screwed me over because values couldn't be arrays. Added condition to detect value type.
46-49 - Rule now needs to be set to in order to work
160-189 - Value for the rule can now be array. Optionally containing sub-arrays where
22, 2333 - In my view is an unnecessary state so I've removed it. Better to just check if isn't empty which I can do directly now because it's public.
191-198 - added rule is_datetime following this method. Example:
https://pastebin.com/KmhvbPFh
46,51 - Replaced empty() with strlen()==0 because if the input was "0" (number zero) then the validation wouldn't work.
78-87 - Optionally you can pass array to the unique for a more complicated query (provided you have this patch). For example:
Code:
"unique"=>["tablename", ["and", ["SomeData","=",1], ["OtherData","=",2]]]
110-147 - Added rules <, >, <=, >=, !=, == for comparing numbers. They will automatically check if value is a number so there's no need to stack it with is_numeric. For example:
Code:
">="=>25
Code:
">"=>"Price"
149-152 - Added rule is_int for excluding floats.
Code:
"is_int"=>true
209-210 - In function addError() added condition to prevent error message duplication.
===
EDIT:
54-55, 62-63, 70-73 - One issue with using array keys as rules is that you can't stack them. I've added an option to pass an array to rules: min, max, matches, <, >, <=, >=, !=, ==. For example:
Code:
">"=>[25,"Price"]
154-158 - Added rule is_timezone for verifying time zone name.
Code:
"is_timezone"=>true
100, 149 - Added
Code:
is_num
Code:
is_numeric
Code:
is_integer
Code:
is_int
160-189 - Added rule in for matching string lowercase.
Code:
"in"=>["a","b","c"]
30, 38-41 - If value is an array then
Code:
sanitize
Code:
Input::get
43-44, 51, 57, 65 - My earlier change to
Code:
strlen
46-49 - Rule
Code:
required
Code:
true
160-189 - Value for the rule
Code:
in
Code:
[["display","value"]]
22, 2333 - In my view
Code:
_passed
Code:
_errors
191-198 - added rule is_datetime following this method. Example:
Code:
"is_datetime"=>"Y-m-d"