From: jumpin-banana Date: Fri, 23 Apr 2010 09:38:42 +0000 (+0200) Subject: validate input function. easy to expand X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=120a75e443cf636f08bc8b6400585dd60391ae2b;p=dolphin.git validate input function. easy to expand --- diff --git a/single-functions/validate-input.php b/single-functions/validate-input.php new file mode 100644 index 0000000..2bdff90 --- /dev/null +++ b/single-functions/validate-input.php @@ -0,0 +1,56 @@ +. + */ + +/** + * validate if given string is correct + * this can easily exapnded with more match patterns + * + * @param string $string + * @param string $mode + */ + function validateInput($string,$mode) { + $ret = false; + if(!empty($string) && !empty($mode)) { + switch ($mode) { + case 'nospace': + $pattern = '/[^\p{L}\p{N}\p{P}]/u'; + $value = preg_replace($pattern, '', $string); + if($string === $value) { + $ret = true; + } + break; + case 'digit': + $pattern = '/[^\p{N}]/u'; + $value = preg_replace($pattern, '', $string); + if($string === $value) { + $ret = true; + } + break; + case 'text': + $pattern = '/[^\p{L}\p{N}\p{P}]/u'; + $value = preg_replace($pattern, '', $string); + if($string === $value) { + $ret = true; + } + break; + } + } + return $ret; +} +?>