[eluser]sorenchr[/eluser]
EDIT: I fixed some misinformation in the documentation.
This is a small albeit useful library I created for validating/sanitizing data. I use it primarily to make sure my data is clean before I throw it in a database.
Using this library is much like using CI's native Form validation library, however it doesn't serve the same purpose. Here's a basic example of how to use it:
Code:
$somedata = "some data we want checked and sanitized";
//run data through the validator
$output = $this->validation->validate($somedata, 'max_length[255]|valid_email|trim|cut[0,10]');
//did the data validate?
if($output == FALSE)
{
echo "data is invalid";
}
else
{
echo "the validated and sanitized data is: ".$output;
}
You can also validate/sanitize an array of data and rules, but it has to be a multidimensional associative array, like so:
Code:
$array = array('string1' => array('somedata' => 'trim|valid_email'),
'string2' => array('somedata' => 'alpha_numeric'));
$output = $this->validation->validate($array);
//did the data validate?
if($output == FALSE)
{
echo "data is invalid";
}
else
{
// here the output would then be the sanitized and validated array.
print_r($output);
}
The library basically iterates over the rules you've provided, as many as you like of course, creating new rules for validation/sanitation is simple and easy.
It then returns the sanitized data, if the data validated. Check the file for all available validation/sanitation methods. The validation function returns FALSE if the data did not validate.
As always, make sure you look through the code before using it. I've checked it myself, but that's not a bug-free guarentee
Place the file in your application/libraries folder and you are set.