Get Website Learn Coding Tech Story

PHP Programming Examples

<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);
   			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!

Learn more about ereg function