getID())) return false; return true; } function isValidMDBOClass($mdbo_classname) { // See if the class exists if (!class_exists($mdbo_classname)) return false; // Make one and return whether it's an MDBO or not. $mdbo = new $mdbo_classname; $retval = ($mdbo instanceof MDBO); unset($mdbo); return $retval; } function isValidString ($input) { return (strlen($input) > 0); } function isValidInt($input, $deny_zero = true) { if (!$deny_zero && ($input == 0)) return true; if (strlen($input < 1) || (intval($input) != $input) || !preg_match('/^[0123456789]+$/', $input)) return false; return true; } function isValidFloat($input) { if (trim($input) == "0") return true; if (strlen($input) < 1 || !is_numeric($input) || !preg_match('/[0-9]*\.?[0-9]*/', $input)) return false; return true; } // isValidYear - using a set date range, tells you whether a 4 digit number is a valid year or not. Default range of 99 years. function isValidYear($input, $four_digit = true, $override_valid_year_range = false) { if (!isValidInt($input)) return false; $digits = $four_digit ? 4 : 2; $yearrange = isValidInt($override_valid_year_range) ? $override_valid_year_range : MDBO_VALID_YEAR_RANGE; if (strlen($input) == $digits) { // Check date range for 4 digit only if ($four_digit && abs(date('Y') - $input) < $yearrange) return true; // 2 digit, any number is fine. else return true; } return false; } // isValidMonth - allows all valid months, 1 through 12. function isValidMonth($input) { if (!isValidInt($input)) return false; return ($input >= 1 && $input <= 12); } // isValidDay - tells you whether a number is a valid day of a month, month is optional function isValidDay($input, $month = false) { if (!isValidInt($input)) return false; $days_in_month = isValidMonth($month)? getMonthDays($month) : MDBO_DEFAULT_DAYS_IN_MONTH; return ($input >= 1 && $input <= $days_in_month); } // isValidAlpha - allows only letters. function isValidAlpha($input) { return ((strlen($input) > 0) && (preg_match('/^[a-zA-Z]+$/', $input))); } // isValidAlphanumeric - allows for all letters, numbers, and space. function isValidAlphanumeric($input, $allow_space = true) { $regex = $allow_space ? '/^[a-zA-Z0-9 ]+$/' : '/^[a-zA-Z0-9]+$/'; return ((strlen($input) > 0) && (preg_match($regex, $input))); } // isValidAlphaNumDash - allows alphanumerics and dashes, no spaces function isValidAlphaNumDash($input) { return ((strlen($input) > 0) && (preg_match('/^[a-zA-Z0-9\-]+$/', $input))); } // isValidAlphaNumDashDot - allows alphanumerics, dash, dot, space function isValidAlphaNumDashDot($input) { return ((strlen($input) > 0) && (preg_match('/^[a-zA-Z0-9\-. ]+$/', $input))); } // isValidParagraph - allows reasonable characters for a paragraph of English text function isValidParagraph($input) { return ((strlen($input) > 0) && (preg_match('/^[a-zA-Z0-9\-\"\'.!?,;: ]+$/', $input))); } // isValidDatetime - allows all valid ISO datetimes: YYYY-MM-DD HH:MM:SS. function isValidDatetime($input) { $regex = "/^(19[0-9]{2}|[2-9][0-9]{3})-((0(1|3|5|7|8)|10|12)-(0[1-9]|1[0-9]|2[0-9]|3[0-1])|(0(4|6|9)|11)-(0[1-9]|1[0-9]|2[0-9]|30)|(02)-(0[1-9]|1[0-9]|2[0-9]))\x20(0[0-9]|1[0-9]|2[0-3])(:[0-5][0-9]){2}$/"; return preg_match($regex, $input) ? true : false; } // isValid10minTime - allows all valid times in 10 minute increments. function isValid10minTime($input) { $regex = "/^[12]?[0-9]\:[0-5]0$/"; return preg_match($regex, $input) ? true : false; } // isValidDate - allows all valid ISO datetimes sans time: YYYY-MM-DD. function isValidDate($input) { $regex = "/^(19[0-9]{2}|[2-9][0-9]{3})[-]?((0(1|3|5|7|8)|10|12)[-]?(0[1-9]|1[0-9]|2[0-9]|3[0-1])|(0(4|6|9)|11)[-]?(0[1-9]|1[0-9]|2[0-9]|30)|(02)[-]?(0[1-9]|1[0-9]|2[0-9]))$/"; return preg_match($regex, $input) ? true : false; } // isValidEmail - allows almost all valid email addresses. It's possible some weird ones are dissallowed... function isValidEmail($input) { $regex = "/^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/"; return preg_match($regex, $input) ? true : false; } // isValidBool - allows the use of textual booleans. function isValidBool($input, $throw_exception = false) { if (is_bool($input) || in_array(strtolower($input), Array("true", "false"))) return true; else if ($throw_exception) throw new Exception("isValidBool: not a boolean!"); else return false; } // isValidFilename - allows simple filenames only - alphanumerics, dots, underscores and dashes, no spaces function isValidFilename($input) { return ((strlen($input) > 0) && (preg_match('/^[a-zA-Z0-9\-_.]+$/', $input))); } // isAssocArray - allows only associative arrays function isAssocArray($arr) { if (!is_array($arr)) return false; return array_keys($arr) != range(0, count($arr) - 1); } // isValidSortOrder - allows only ASC or DESC, case insensitive function isValidSortOrder($sort) { return (in_array(strtolower($sort), Array('asc', 'desc'))); } // isValidDomain - allows only valid domain names function isValidDomain($domainname) { return preg_match('/^([a-z0-9]([-a-z0-9]*[a-z0-9])?\\.)+((a[cdefgilmnoqrstuwxz]|aero|arpa)|(b[abdefghijmnorstvwyz]|biz)|(c[acdfghiklmnorsuvxyz]|cat|com|coop)|d[ejkmoz]|(e[ceghrstu]|edu)|f[ijkmor]|(g[abdefghilmnpqrstuwy]|gov)|h[kmnrtu]|(i[delmnoqrst]|info|int)|(j[emop]|jobs)|k[eghimnprwyz]|l[abcikrstuvy]|(m[acdghklmnopqrstuvwxyz]|mil|mobi|museum)|(n[acefgilopruz]|name|net)|(om|org)|(p[aefghklmnrstwy]|pro)|qa|r[eouw]|s[abcdeghijklmnortvyz]|(t[cdfghjklmnoprtvwz]|travel)|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw])$/', $domainname) ? true : false; } // isValidHostname - allows only valid hostnames (including full domain) function isValidHostname($hostname, $full_domain = true) { if ($full_domain || strpos($hostname, '.') !== false) { $result = preg_match('/^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$/', $hostname) ? true : false; } else $result = ((strlen($hostname) > 0) && (preg_match('/^[a-zA-Z0-9_-]+$/', $hostname))); return $result; } // isValidNetgroup - allows for all letters, numbers, and underscore. function isValidNetgroup($input) { return ((strlen($input) > 0) && (preg_match('/^[a-zA-Z0-9_]+$/', $input))); } // isValidMACAddress - allows only valid Ethernet MAC Addresses. function isValidMACAddress($mac) { return preg_match('/^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/', $mac) ? true : false; } // isValidIP - allows only valid IPv4 IPs. function isValidIP($ip) { return preg_match('/^((0|1[0-9]{0,2}|2[0-9]{0,1}|2[0-4][0-9]|25[0-5]|[3-9][0-9]{0,1})\.){3}(0|1[0-9]{0,2}|2[0-9]{0,1}|2[0-4][0-9]|25[0-5]|[3-9][0-9]{0,1})$/', $ip) ? true : false; } // isValidURL - allows only valid URLs. function isValidURL($url) { // Relative URLs are OK if (isValidRelativeURL($url)) return true; return filter_var($url, FILTER_VALIDATE_URL) ? true : false; } // isValidRelativeURL - allows relative URLS (/foo/whatever.php?foo=bar) function isValidRelativeURL($url) { return preg_match('/[a-zA-Z0-9_.\/?#=]+/', $url) ? true : false; } // isValidUsername - allows only valid usernames. function isValidUsername($username) { return preg_match('/[a-zA-Z0-9]+/', $username) ? true : false; } // isValidLDAPPath - allows LDAP paths, with or without a CN in front. function isValidLDAPPath($path) { return preg_match("/^((CN=(['\w\d\s\-\&\.]+(\\/)*(\\,)*)+,\s*)*(OU=(['\w\d\s\-\&\.]+(\\/)*(\\,)*)+,\s*)*(DC=['\w\d\s\-\&]+[,]*\s*){1,}(DC=['\w\d\s\-\&]+\s*){1})$/", $path) ? true : false; } // isValidSQLArray - allows SQL arrays in the format of ["item", "item", "item"] // Spaces around commas are not required // Both single and doublequotes are okay but you gotta quote it unless it's a valid number function isValidSQLArray($arr) { // Check for brackets if (substr($arr, 0, 1) != "(" || substr($arr, -1) != ")") return false; // Chop the brackets off $arr = substr($arr, 1, -1); // Explode and check each part $arex = explode(",", $arr); foreach($arex as $aritem) { $aritem = trim($aritem); // Doublequoted string if ((substr($aritem, 0, 1) == '"') && (substr($aritem, -1) == '"')) $quotechar = '"'; // Singlequoted string else if ((substr($aritem, 0, 1) == "'") && (substr($aritem, -1) == "'")) $quotechar = "'"; // Valid number else if (isValidFloat($aritem)) continue; // Invalid, drop out completely - no valid quoting + not a number else return false; // Chop the quotes off $aritem = substr($aritem, 1, -1); // Check to see if a quoted string contains its own quote type unescaped if (preg_match("/[^\\\\]$quotechar/", $aritem) != 0) return false; } return true; function isValidGUID($guid) { return preg_match("^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$", $guid) ? true : false; } } ?>