about summary refs log tree commit diff
path: root/sourcecodes/input_validate.php
blob: 06843a57a6c7baaec8d39c375c24a7dc8cc83d8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
//This file will contain input validation functions.

function valid_keyval($keyval)
{
  $keyval = trim((string)($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((string)($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;
}