-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp5_validation.php
More file actions
35 lines (29 loc) · 843 Bytes
/
p5_validation.php
File metadata and controls
35 lines (29 loc) · 843 Bytes
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
<?php
// define variables and set to empty values
$name = $email = $gender = $password = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
echo "Name is required<br/>";
}
if ( empty($_POST["email"]) || strpos($_POST["email"], '@')==false ) {
echo "Email is required<br/>";
}
if(!empty($_POST["password"])) {
$password = test_input($_POST["password"]);
if(!preg_match("#[0-9]+#",$password)) {
echo "you must enter at least one number<br/>";
}
}else{
echo "Password is required<br/>";
}
if (empty($_POST["gender"])) {
echo "Gender is required<br/>";
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>