Skip to content

Instantly share code, notes, and snippets.

@honno
Created June 3, 2018 19:32
Show Gist options
  • Save honno/52728b12637bde3b36050317fda86f5a to your computer and use it in GitHub Desktop.
Save honno/52728b12637bde3b36050317fda86f5a to your computer and use it in GitHub Desktop.
<?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