-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.php
More file actions
47 lines (37 loc) · 1.11 KB
/
validate.php
File metadata and controls
47 lines (37 loc) · 1.11 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
<?php
// Quick function to loop through regexs and compare to what is in _POST
//
// $regs -> associative array of regular expressions
// $ferrors -> error messages to display to the users asociative array
function validatePost( $regs , $ferrors )
{
$errors = array();
foreach( $regs as $k => $v )
{
if(!ereg( $v , $_POST[$k] ) )
{
$errors[$k] = $ferrors[$k];
}
}
return $errors;
}
// has the post been submitted?
if( count( $_POST ) )
{
// yes it has been submitted so lets validate
$regs['lName'] = "^[[:alpha:]\ -]+$"; // require a alpha
$regs['fName'] = "^[[:alpha:]\ -]+$"; // require a alpha
$regs['email'] = "^..*\@..*$"; // VERY simple email check
// Use google to find better
// Ok here are the error message to display when it is bad
$ferrors['last_name'] = "Last name required";
$ferrors['first_name'] = "First name required";
$ferrors['email'] = "Email name required";
$errors = validatePost( $regs , $ferrors );
// Do we have errors?
if( count( $errors ) == 0 )
{
echo 'It\'s all good';
}
}
?>