Created
June 3, 2018 19:32
-
-
Save honno/52728b12637bde3b36050317fda86f5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function para($msg) { echo "<p>$msg</p>"; } | |
function error($msg) { | |
$valid = false; | |
para($msg); | |
} | |
$name = trim($_REQUEST["name"]); | |
$email = trim($_REQUEST["email"]); | |
$age = trim($_REQUEST["age"]); | |
$comments = trim($_REQUEST["comments"]); | |
$valid = true; | |
if (!preg_match('/[A-Za-z\-\.]{1,20}/', $name)) { | |
error("Name should only contain letters, hyphens and dots and no more than than 20 characters."); | |
} | |
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { | |
error("Your email is invalid."); | |
} | |
if (!preg_match('/\d{2}/', $age)) { | |
error("Your age is invalid."); | |
} | |
if (empty($comments)) { | |
error("You have not entered your comments."); | |
} | |
if ($valid) { | |
para("Thank you"); | |
para("Name: $name, Email: $email, Age: $age"); | |
para("Comments"); | |
para($comments); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment