-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidate.php
More file actions
64 lines (64 loc) · 1.99 KB
/
validate.php
File metadata and controls
64 lines (64 loc) · 1.99 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
<?php
//validate form data//
$errors=0;
if(trim($first_name)=='') {
echo "<div id='alert'>first_name can't be blank</div>";
$errors=1;
}
if(trim($last_name)=='') {
echo "<div id='alert'>last name can't be blank</div>";
$errors=1;
}
if(trim($street_address)=='') {
echo "<div id='alert'>street address can't be blank</div>";
$errors=1;
}
if(trim($username)=='') {
echo "<div id='alert'>username can't be blank</div>";
$errors=1;
}
if($action=='register' && trim($password)=='') {
echo "<div id='alert'>password can't be blank</div>";
$errors=1;
}
elseif (!preg_match("/^(?=^.{7,}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*$/", $password)) {
echo "<div id='alert'>password must be at least 7 chars long with one lower-case, one upper-case char, and one digit</div>";
$errors=1;
}
if($action=='register' && trim($confirm_password)=='') {
echo "<div id='alert'>confirm password can't be blank</div>";
$errors=1;
}
if($action=='register' && $password!=$confirm_password) {
echo "<div id='alert'>passwords don't match</div>";
$errors=1;
}
if(trim($birth_month)=='') {
echo "<div id='alert'>birth month can't be blank</div>";
$errors=1;
}
if(trim($birth_day)=='') {
echo "<div id='alert'>birth day can't be blank</div>";
$errors=1;
}
if(trim($birth_year)=='') {
echo "<div id='alert'>birth year can't be blank</div>";
$errors=1;
}
if(trim($email)=='') {
echo "<div id='alert'>email can't be blank</div>";
$errors=1;
}
elseif (!preg_match("/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/i", $email)) {
echo "<div id='alert'>email address format is invalid: x@y.z</div>";
$errors=1;
}
if($action=='register' && trim($security_question)=='') {
echo "<div id='alert'>security question can't be blank</div>";
$errors=1;
}
if($action=='register' && trim($security_answer)=='') {
echo "<div id='alert'>security answer can't be blank</div>";
$errors=1;
}
?>