-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.php
More file actions
81 lines (79 loc) · 1.67 KB
/
Copy pathvalidate.php
File metadata and controls
81 lines (79 loc) · 1.67 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
function has_max_length($value,$max)//length if block
{
return strlen($value) <= $max;
}
function validate_max_lengths($fields_max_length)//function for length
{
global $errors;
foreach($fields_max_length as $field => $max)
{
$value=trim($_POST[$field]);
if(!has_max_length($value,$max))
{
$errors[$field]=ucfirst($field) . "is to long";
}
}
}
function has_min_length($value,$min)//min length if checking
{
return strlen($value)<$min;
}
function validate_min_lengths($fields_min_length)//min length function
{
global $errors;
foreach ($fields_min_length as $field => $min)
{
$value=trim($_POST[$field]);
if(has_min_length($value,$min))
{
$errors[$field]=ucfirst($field) . " is to short";
}
}
}
function has_presence($value)//not empty block
{
return isset($value) && $value!=="";
}
function all_prestnt($name_fields_presence)//function for not empty
{
global $errors;
foreach ($name_fields_presence as $field)
{
$value=trim($_POST[$field]);
if(!has_presence($value))
{
$errors[$field]=ucfirst($field) . " cannot be blank ";
}
}
}
function form_errors($errors=array())//errors printing
{
$output="";
if(!empty($errors))
{
$output="<div class=\"error\">";
$output .="Please fix the following errors:";
$output .="<ul>";
foreach($errors as $key=>$error)
{
$output .="<li>{$error}</li>";
}
$output .="</ul>";
$output .="</div>";
}
return $output;
}
function all_regular($name_regular)//regula format function
{
global $errors;
foreach ($name_regular as $fields)
{
$value=trim($_POST[$fields]);
if (!preg_match("/^[a-zA-Z ]*$/",$value))
{
$errors[$fields] =ucfirst($fields) . " can have only letters ";
}
}
}
?>