From 120a75e443cf636f08bc8b6400585dd60391ae2b Mon Sep 17 00:00:00 2001 From: jumpin-banana Date: Fri, 23 Apr 2010 11:38:42 +0200 Subject: [PATCH] validate input function. easy to expand --- single-functions/validate-input.php | 56 +++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 single-functions/validate-input.php 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; +} +?> -- 2.39.5