Skip to content

Instantly share code, notes, and snippets.

@sarfraznawaz2005
Last active October 12, 2015 18:27
Show Gist options
  • Save sarfraznawaz2005/63db77df52c35110ca0f to your computer and use it in GitHub Desktop.
Save sarfraznawaz2005/63db77df52c35110ca0f to your computer and use it in GitHub Desktop.
function to validate user input
<?php
/**
* This function can be used to check the sanity of variables
*
* @access private
*
* @param string $type The type of variable can be bool, float, numeric, string, array, or object
* @param string $string The variable name you would like to check
* @param string $length The maximum length of the variable
*
* return bool
*/
function sanityCheck($string, $type, $length){
// assign the type
$type = 'is_'.$type;
if(!$type($string))
{
return FALSE;
}
// now we see if there is anything in the string
elseif(empty($string))
{
return FALSE;
}
// then we check how long the string is
elseif(strlen($string) > $length)
{
return FALSE;
}
else
{
// if all is well, we return TRUE
return TRUE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment