Check Email Function

Started on the old forum in July 2009 · view the original in the archive · old links redirect here

4 replies · 811 views · started 17 years ago · 1 min read

4 participants
anderson Developer · 146 posts #1
function check_email($email)
{
  {
    if( (preg_match('/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/', $email)) ||  
        (preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/',$email)) ) {  
        $dom = explode('@', $email); 
        if(checkdnsrr($dom[1].'.', 'MX') ) return true; 
        if(checkdnsrr($dom[1].'.', 'A') ) return true; 
        if(checkdnsrr($dom[1].'.', 'CNAME') ) return true; 
    } 
    return false; 
}

Hi I use this check email function but not working properly. It cant check email even when a user write "no email now" in the email field.

If anybody has a better function please share hare. I need.

Wait...

rukiya Lead · 569 posts #2
function check_email($email) 
{ 
  { 
    if( (preg_match('/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/', $email)) ||   
        (preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/',$email)) ) {   
        $dom = explode('@', $email);  
        if(checkdnsrr($dom[1].'.', 'MX') ) return true;  
        if(checkdnsrr($dom[1].'.', 'A') ) return true;  
        if(checkdnsrr($dom[1].'.', 'CNAME') ) return true; 
        if($email<>'' ) return true;
    }  
    return false;  
} 
blackhowk Senior · 411 posts #3

another email function

another email function

function isValidEmail($mail){
    return eregi("^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)*(\.[a-zA-Z0-9]{2,3})$", $mail);
            //( "/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $email))
            //('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/',$email)) )
            //
}
   if (isValidEmail($mail)) {
echo "do something";
}
friend Developer · 112 posts #4

whats d script?

blackhowk Senior · 411 posts #5
[COLOR=#000000][COLOR=#0000BB]<?php 
[/COLOR][COLOR=#007700]function [/COLOR][COLOR=#0000BB]check_email[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$mail_address[/COLOR][COLOR=#007700]) { 
    [/COLOR][COLOR=#0000BB]$pattern [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]"/^[\w-]+(\.[\w-]+)*@"[/COLOR][COLOR=#007700]; 
    [/COLOR][COLOR=#0000BB]$pattern [/COLOR][COLOR=#007700].= [/COLOR][COLOR=#DD0000]"([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})$/i"[/COLOR][COLOR=#007700]; 
    if ([/COLOR][COLOR=#0000BB]preg_match[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$pattern[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$mail_address[/COLOR][COLOR=#007700])) { 
        [/COLOR][COLOR=#0000BB]$parts [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]explode[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"@"[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$mail_address[/COLOR][COLOR=#007700]); 
        if ([/COLOR][COLOR=#0000BB]checkdnsrr[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$parts[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700]], [/COLOR][COLOR=#DD0000]"MX"[/COLOR][COLOR=#007700])){ 
            echo [/COLOR][COLOR=#DD0000]"The e-mail address is valid."[/COLOR][COLOR=#007700]; 
            [/COLOR][COLOR=#FF8000]// return true; 
        [/COLOR][COLOR=#007700]} else { 
            echo [/COLOR][COLOR=#DD0000]"The e-mail host is not valid."[/COLOR][COLOR=#007700]; 
            [/COLOR][COLOR=#FF8000]// return false; 
        [/COLOR][COLOR=#007700]} 
    } else { 
        echo [/COLOR][COLOR=#DD0000]"The e-mail address contains invalid charcters."[/COLOR][COLOR=#007700]; 
        [/COLOR][COLOR=#FF8000]// return false; 
    [/COLOR][COLOR=#007700]} 
} 

[/COLOR][COLOR=#FF8000]// This is how to use 
[/COLOR][COLOR=#0000BB]check_email[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"INFO@google.co.uk"[/COLOR][COLOR=#007700]); 
[/COLOR][COLOR=#0000BB]?>
[/COLOR][/COLOR]

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close