Monday, May 17, 2010

PHP Validate Email Address

Validate email address use PHP


HTML Code:
Copy this code and save as form.php

<form action="validate.php" method="post">
<input name="email" id="email" type="text"/>
<input name="submit" type="submit" value="Validate">
</form>

PHP Code
Copy this code and save as validate.php

<?
$email = $_REQUEST['email'];
if(!ereg('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$',$email)){
echo "Not valid mail address";
} else {
echo "Valid mail address";
}
?>



No comments: