--- /dev/null
+<?php
+/**
+ * dolphin. Collection of usefull PHP skeletons.
+ * Copyright (C) 2009 Johannes 'Banana' Keßler
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * 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;
+}
+?>