Last active
October 12, 2015 18:27
-
-
Save sarfraznawaz2005/63db77df52c35110ca0f to your computer and use it in GitHub Desktop.
function to validate user input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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