[Release]E-mail validity checker for register pages!

03/18/2010 23:04 walmartboi#1
Well, I got a bit bored, and decided I need something like this, and you guys do too, so here's a little e-mail validity checker I coded up:

PHP Code:
<?php
function checkemail($email)
{
  if (!
ereg("^[^@]{1,64}@[^@]{1,255}$", $email))
  {
    return 
false;
  }
  
$email_array = explode("@", $email);
  
$local_array = explode(".", $email_array[0]);
  for (
$i = 0; $i < sizeof($local_array); $i++)
  {
    if(!
ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&↪'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) 
    {
      return 
false;
    }
  }
  if (!
ereg("^\[?[0-9\.]+\]?$", $email_array[1]))
  {
    
$domain_array = explode(".", $email_array[1]);
    if (
sizeof($domain_array) < 2)
    {
        return 
false;
    }
    for (
$i = 0; $i < sizeof($domain_array); $i++)
    {
      if(!
ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|↪([A-Za-z0-9]+))$", $domain_array[$i]))
      {
        return 
false;
      }
    }
  }
  return 
true;
}
?>
Add that function to the TOP of your register completion page, and use it like this in all your checks for it:

PHP Code:
$email = trim($_POST['email']);  
if(!
checkemail($email))
{ 
 echo 
'Invalid email address!';
}
else 
{
 echo 
'Email address is valid';
} 
NOTE: If you don't know what this does, just don't bother posting.
ANOTHER NOTE: If you use this on your site, please give small little credits to how I helped :)
03/18/2010 23:11 xScott#2
goodjob :), php looks nuts o-o
03/18/2010 23:13 walmartboi#3
Quote:
Originally Posted by xScott View Post
goodjob :), php looks nuts o-o
Thanks for the feedback :P It actually wasn't too hard to code, considering how similar PHP is to C#. It works perfectly btw. :cool:
03/18/2010 23:18 Arcо#4
<3 I love it!
03/18/2010 23:43 PeTe Ninja#5
You could also check it just do something like...


$results = mysql_query(Select * FROM `accounts` Where `email` == $email);

if ($results == 1)

echo 'Email already in use';
else

echo 'Good email';


something of that knowledge.
03/18/2010 23:47 ~Falcon#6
Quote:
Originally Posted by PeTe Ninja View Post
You could also check it just do something like...


$results = mysql_query(Select * FROM `accounts` Where `email` == $email);

if ($results == 1)

echo 'Email already in use';
else

echo 'Good email';


something of that knowledge.
He's checking whether its a valid e-mail, not whether its already in use.
03/18/2010 23:50 PeTe Ninja#7
Quote:
Originally Posted by ~Falcon View Post
He's checking whether its a valid e-mail, not whether its already in use.
I know.. I showed them if you want to check if it's in use.. I can read PHP :)
03/19/2010 00:00 walmartboi#8
Quote:
Originally Posted by PeTe Ninja View Post
You could also check it just do something like...


$results = mysql_query(Select * FROM `accounts` Where `email` == $email);

if ($results == 1)

echo 'Email already in use';
else

echo 'Good email';


something of that knowledge.
This script is only to check if the email address is real, not some jibberish stuff a spammer typed in.
03/19/2010 00:44 Luiz01#9
Nice ! I liked it.
03/19/2010 00:46 walmartboi#10
Quote:
Originally Posted by Luiz01 View Post
Nice ! I liked it.
Thanks.
03/19/2010 03:00 LegalConquer#11
why dont u add a captcha XD
03/19/2010 12:21 BEanErzzz#12
AJAX version using the RFC official email validity regex string.

Code:
function isValidEmail (email){
    return /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(email);
}
function checkEmail(){
    if(isValidEmail(txtEmail.value)){
        SetMessage(msgEmail, "The email appears valid", "green");
        emailValid = true;
    }else{
        SetMessage(msgEmail, "The email appears invalid", "red");
        emailValid = false;
    }
    setPostValid();
}
Preview here: [Only registered and activated users can see links. Click Here To Register...]
03/19/2010 22:10 walmartboi#13
Quote:
Originally Posted by BEanErzzz View Post
AJAX version using the RFC official email validity regex string.

Code:
function isValidEmail (email){
    return /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(email);
}
function checkEmail(){
    if(isValidEmail(txtEmail.value)){
        SetMessage(msgEmail, "The email appears valid", "green");
        emailValid = true;
    }else{
        SetMessage(msgEmail, "The email appears invalid", "red");
        emailValid = false;
    }
    setPostValid();
}
Preview here: [Only registered and activated users can see links. Click Here To Register...]
Looks nice, but I made mine from scratch, so you have to give me some kudos for that :P
03/20/2010 02:09 PeTe Ninja#14
Quote:
Originally Posted by walmartboi View Post
This script is only to check if the email address is real, not some jibberish stuff a spammer typed in.
does anyone read my posts? or do you just look at the code..
03/20/2010 03:23 Arcо#15
Quote:
Originally Posted by LegalConquer View Post
why dont u add a captcha XD
I would love if someone released a captcha reg lol.