E-mail Validation

<html>
	<head>
		<title>Email Validation</title>
	</head>
	<body>
		<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
			<input type="email" autocomplete="off" required name="email" placeholder="Enter a email address" />
			<input type="submit" value="Validate" />
		</form>
		<?php
			if(isset($_POST['email'])) {
				$email = $_POST['email'];
   			$valid = ereg("^[^@ ][email protected][^@ ]+\.[^@ \.]+$", $email);
   			if ($valid)
      				echo "<br />It's a valid email address!";
   			else
	      			echo "<br />It's a invalid email address!";
   		}
		?>
	</body>
</html>



/* Output */
E-mail: [email protected]
It's a invalid email address!

/* ------------------------------------------ */

E-mail: [email protected]
It's a valid email address!

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!