Skip to content

Instantly share code, notes, and snippets.

@edward-jimenez
Created May 6, 2018 22:39
Show Gist options
  • Save edward-jimenez/2f93eb36c358e19da793e037400c4ac1 to your computer and use it in GitHub Desktop.
Save edward-jimenez/2f93eb36c358e19da793e037400c4ac1 to your computer and use it in GitHub Desktop.
Check whether a POST variable contains the '@' symbol in an email input
<?php
/*
Checking if an email address contains the '@' symbol
using the PHP strpos function
*/
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Email Checker</title>
</head>
<body>
<?php if($_SERVER['REQUEST_METHOD'] == 'GET') { ?>
<form method="POST" action="email-check.php" >
<input type="email" name="email" placeholder="email" />
<input type="submit" name="submit" value="Submit" />
</form>
<?php } else {
/* Returns the position of the '@' symbol. If it is not found
then false is returned.
*/
if(strpos($_POST['email'], '@') === false ) {
print 'There was no @ in the e-mail address!';
}
} ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment