Validate
Function: validate
Visibility: public
Parameter: validate($string,$type,$length,$constraint,$varName)
Description:
The simplest way to validate string or array by giving a requested type and length. With the ability to choose constraint that will invoke an error if the string or array is not meet by.
Parameters:
(required) - string|array - $string - The string or array we want to test.
(optional) - string - $type - The type of test we want to run on the $string, such as: any kind of integer / varchar / characters / filename / url / email / ip / date / xss check.
(optional) - string - $constraint - Here we choose if this string or array is required or optional.
(optional) - string - $varName - The string or array name - So the function can return it with an error - If occur.
(optional) - string|int - $length - If we want to set max chars we will set an integer. If we want to set also a minimum length we will set it at range like: xx-xx - Of min and max.
Return:
string|array|bool|mixed - The string or array after the validation - If test was negative, the string will be wiped.
Callable from (extended classes):
application: controller,view
advanced: controller,view
operators: controller,view
api: controller,view
example: 1
We want to validate user input from a param we got. User inputed: "I live in Haifa.". Since validation passed, we got exactly what we sent.
How to call (example):
Possible outcome (example):
Output:
example: 2
We can also send an array, the function will check every value and make us a result.
How to call (example):
Possible outcome (example):
Output: