Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Email Validation
Index -> Programming, PHP -> PHP Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
alpesh




PostPosted: Sat Mar 10, 2007 7:57 am   Post subject: Email Validation

Quote:

<?php

if (!isset($email)){
die("Host name value wasn't properly submitted.Retry.");
}

if(empty($email)) {
die("Hostname field was left blank ! Retry.");
}

if ( (strlen($email) < 3) || (strlen($email) > 200)) {
die("Invalid E-mail address, E-mail address too long or too short.");
} elseif(!ereg("@",$email)) {
die("Invalid E-mail address, no @ symbol found");
} else {
echo "".$email." is correct in format.<br>";
}

list($username,$hostname) = split("@",$email);

if ( (empty($username)) or (empty($hostname)) ) {
die("username or host name section is not valid.");
}

if(checkdnsrr($hostname)) {
echo "". $email ." hostname has a valid MX record !<br>";
} else {
die("". $email ." hostname does not exist");
}
?>
Sponsor
Sponsor
Sponsor
sponsor
PaulButler




PostPosted: Sat Mar 10, 2007 10:32 am   Post subject: RE:Email Validation

Cool... but it looks like any character is accepted in the username part of the email addresss... From what I can tell, !@#$%^&*()_-=+@gmail.com would be considered a valid address.

I usually limit email checking to a simple regex like this:

php:

function validEmail($email){
     return preg_match('/^[a-z0-9_.+-]+@(?:[a-z0-9-]+\\.)+[a-z]{2,6}$/', $email);
}


I didn't know it would be so easy to verify that an MX record existed at the email's hostname... Maybe I will start doing that from now on.
Display posts from previous:   
   Index -> Programming, PHP -> PHP Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: