SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru worchyld's Avatar
    Join Date
    Jul 2003
    Location
    Newcastle upon Tyne
    Posts
    909
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Validating email against a .org.uk address

    I have the following which seems to validate email address pretty well - however it doesn't seem to work against a .org.uk address (which is one my work addresses).

    How do I add to the eregi part to find an optional .org.uk?

    Thanks for any help you can give.

    Code:
    function validEmail($email)  
    {  
    $return = array();   
        if (!eregi("^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z][-.0-9a-z]*\\.[a-z]{2,4}[.]?$",$email, $check)) 
        { 
            $return["status"] = false;  
            $return["msg"] = 'Error: Invalid e-mail address.';          
            return $return;  
        }  
        $host = substr(strstr($check[0], '@'), 1); 
        if (!checkdnsrr($host.'.',"MX"))  
        {
            $return["status"] = false;  
            $return["msg"] = 'Error: Invalid host';          
            return $return;  
        }
        $return["status"] = true;  
        $return["msg"] = $email;  
        return $return;  
    } // END FUNCTION

  2. #2
    SitePoint Addict lveale's Avatar
    Join Date
    Jun 2001
    Location
    Dublin
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This part is the dot domain check.
    PHP Code:
    [a-z]{2,4}[.]?$",$email$check)) 
    Adding a dot in there and allowing more characters may be what you need
    PHP Code:
    [a-z.]{2,6}[.]?$",$email$check)) 

  3. #3
    SitePoint Guru worchyld's Avatar
    Join Date
    Jul 2003
    Location
    Newcastle upon Tyne
    Posts
    909
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So changing 2,4 to 2,6 should work? Mmm, I'll give it a try - thanks a lot.

  4. #4
    SitePoint Guru worchyld's Avatar
    Join Date
    Jul 2003
    Location
    Newcastle upon Tyne
    Posts
    909
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope, that didn't work...it still comes back as a bad address... Are there any other alternatives which will help?

  5. #5
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try
    PHP Code:
    eregi("^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z][-.0-9a-z]*(\\.[a-z]{2,4})+[.]?$"$email$check

  6. #6
    SitePoint Guru worchyld's Avatar
    Join Date
    Jul 2003
    Location
    Newcastle upon Tyne
    Posts
    909
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that.

    It turns out that the following part of the code flags up an error if its a .org.uk address:

    Code:
        $host = substr(strstr($check[0], '@'), 1); 
    	    if (!checkdnsrr($host.'.',"MX"))  
    	    {
    	        $return["status"] = false;  
    	        $return["msg"] = 'Error: Invalid host';          
    			return $return;  
    	    }

  7. #7
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i use this:
    it simply checks the structure and that's fine with me.
    If someone wants to provide a wrong email address, he can do it anyway.

    PHP Code:
    preg_match('/^[^@\s]+@([-A-Z0-9]+\.)+[A-Z]{2,6}$/i'trim($email)); 
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  8. #8
    SitePoint Guru worchyld's Avatar
    Join Date
    Jul 2003
    Location
    Newcastle upon Tyne
    Posts
    909
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, thanks all - I've got enough to run with.

    Thanks again.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •