Sunday, July 8, 2012

Validate an E-Mail Address with PHP, complete script

Validate an E-Mail Address with PHPThis tutorial will teach you how to validate a e-mail id using regular expression to control email Spam. In this tutorial I used ternary operator to filter the values coming from the input box and avoid errors.

Complete Coding is here


<?php
$email=(isset($_POST['email']))?trim($_POST['email']):'';
function verify($email){
    if(!preg_match('/^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,4})$/',$email)){
        return false;
    } else {
        return $email;
    }
}
if(isset($_POST['submit'])){
        if(verify($email)){
            echo $email." is a valid E-mail ID";
        } else {
            echo $email." is an invalid E-mail ID";
        }       
    }
?>
<form action="" method="post">
<input type="text" name="email" value="<?php echo $email;?>"/><br/>
<input type="submit" name="submit" value="validate" />
</form>

PickMe
Delicious Save this on Delicious

1 comment :

  1. Thanks for your ideas. You can also find the details on Webguru, at the Web Designing and Development. The main object of the Webguru is to provide quality web services and is among the few software development Web Design Company Bangalore | Website Designing Company Bangalore

    ReplyDelete

If you have any Question , Suggestion or idea then please comment regarding the post.