-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_error_functions.php
More file actions
51 lines (48 loc) · 1.4 KB
/
validate_error_functions.php
File metadata and controls
51 lines (48 loc) · 1.4 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
// Created by Aaron C. 09/25/2024 Finished: 12/01/2024
// Local variables
$errorCount = 0;
// Validate input function
/**
* Validates input data.
*
* @param mixed $data Data to validate.
* @param string $entryName Name of the entry being validated.
* @return string Validated data.
*/
function validate_input($data, $entryName): String{
global $errorCount;
$isValid = false;
$pattern = "[^;,.?\"'<>!#$%^&*()_+=-]";
if(empty($data)){
display_error($entryName, $isValid);
$data = "";
return $data;
}
else if(preg_match($pattern, $data)){
$isValid = true;
display_error($entryName, $isValid);
$data = "";
return $data;
}
return $data;
}
// Display error function
/**
* Displays an error message and increments the error count.
*
* @param string $entryName Name of the entry that caused the error.
*/
function display_error($entryName, $isvalid){
global $errorCount;
if($isvalid == true){
echo "illegal characters found in \"$entryName\"<br>";
$errorCount++;
}
else{
echo "The field \"$entryName\" is required. Error count: \"$errorCount\"<br>";
$errorCount++;
}
}
// End of function list
?>