]> 91.132.146.200 Git - dolphin.git/commitdiff
validate input function. easy to expand
authorjumpin-banana <jumpin.banana@gmail.com>
Fri, 23 Apr 2010 09:38:42 +0000 (11:38 +0200)
committerjumpin-banana <jumpin.banana@gmail.com>
Fri, 23 Apr 2010 09:38:42 +0000 (11:38 +0200)
single-functions/validate-input.php [new file with mode: 0644]

diff --git a/single-functions/validate-input.php b/single-functions/validate-input.php
new file mode 100644 (file)
index 0000000..2bdff90
--- /dev/null
@@ -0,0 +1,56 @@
+<?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;
+}
+?>