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:
">="=>25Code:
">"=>"Price"149-152 - Added rule is_int for excluding floats.
Code:
"is_int"=>true209-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"=>true100, 149 - Added
Code:
is_numCode:
is_numericCode:
is_integerCode:
is_int160-189 - Added rule in for matching string lowercase.
Code:
"in"=>["a","b","c"]30, 38-41 - If value is an array then
Code:
sanitizeCode:
Input::get43-44, 51, 57, 65 - My earlier change to
Code:
strlen46-49 - Rule
Code:
requiredCode:
true160-189 - Value for the rule
Code:
inCode:
[["display","value"]]22, 2333 - In my view
Code:
_passedCode:
_errors191-198 - added rule is_datetime following this method. Example:
Code:
"is_datetime"=>"Y-m-d"