about summary refs log tree commit diff
path: root/sourcecodes/input_validate.php
diff options
context:
space:
mode:
Diffstat (limited to 'sourcecodes/input_validate.php')
-rw-r--r--sourcecodes/input_validate.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/sourcecodes/input_validate.php b/sourcecodes/input_validate.php
new file mode 100644
index 00000000..7c9dbe60
--- /dev/null
+++ b/sourcecodes/input_validate.php
@@ -0,0 +1,30 @@
+<?php
+//This file will contain input validation functions.
+
+function valid_keyval($keyval)
+{
+  $keyval = trim($keyval);
+  $keyval = stripslashes($keyval);
+  $keyval = htmlspecialchars($keyval);
+  //check if keyval contains only uppercase or lowercase letters.
+  if (!preg_match('/^[a-zA-Z]+$/',$keyval)) {
+    header("Location: keyval_error.php");
+  }
+  if (strlen($keyval)!=3) {
+    header("Location: keyval_error.php");
+  }
+  return $keyval;
+}
+
+
+function valid_input($input)
+{
+  $input = trim($input);
+  $input = stripslashes($input);
+  $input = htmlspecialchars($input);
+  //check if keyval contains only letters, numbers, hyphens, underscore, periods, or whitespace.
+  if (!preg_match('/^[-A-Za-z\d\ \t\r\n_\.]+$/',$input)) {
+    header("Location: input_error.php");
+  }
+  return $input;
+}