NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Modifying website registration.

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 05-24-2007, 08:24 PM THREAD STARTER               #1 (permalink)
NamePros Regular
 
ZeniusIVanisher's Avatar
Join Date: Apr 2006
Location: lolz
Posts: 715
ZeniusIVanisher is a splendid one to beholdZeniusIVanisher is a splendid one to beholdZeniusIVanisher is a splendid one to beholdZeniusIVanisher is a splendid one to beholdZeniusIVanisher is a splendid one to beholdZeniusIVanisher is a splendid one to beholdZeniusIVanisher is a splendid one to beholdZeniusIVanisher is a splendid one to behold
 



Modifying website registration.


First off, I'm a complete n00b with this kind of stuff, so bare with me

Okay. Say I have a website script. I want to modify it so people can ONLY register if they have 1 specific e-mail domain. for example: it will only allow members with yahoo.com e-mails to register. if you have gmail, it won't work.

is this possible using php? (well, i'd imagine it would be php)

thanks so much in advance
__________________
●available for design work
●pm if interested
ZeniusIVanisher is offline  
Old 05-24-2007, 09:52 PM   #2 (permalink)
cef
NamePros Regular
Join Date: May 2004
Location: NYC
Posts: 236
cef is a jewel in the roughcef is a jewel in the roughcef is a jewel in the rough
 


Animal Rescue
Here you go:

PHP Code:
<?php

/**************************************************************************
* validate an email address 
*
* 1.   email address must have a valid format
* 2.   email address must be from a specific domain
*
* Parameters:
*        $email        The FULL email address, e.g. myname@mydomain.com
*        $domain        The valid domain, e.g domain.com, yahoo.com, etc.
*
* Returns:
*        true or false as the case may be.
*
* The test is case INsensitive.
**************************************************************************/
function validate_email($email,$domain)
????: NamePros.com http://www.namepros.com/programming/331690-modifying-website-registration.html
{
    return !
preg_match('/^([0-9a-z]+[-._+&])*[0-9a-z]+(@' $domain ')$/i'$email) ? false true;
}


/**************************************************************************
* TEST CODE BELOW
**************************************************************************/

// define the valid email domain here
define('EMAIL_DOMAIN''yahoo.com');

// test address 1
$addr 'abcd@YAHOO.com';

$valid validate_email($addr,EMAIL_DOMAIN);
print_result($valid);

// test address 2
$addr 'abcd@gmail.com';

$valid validate_email($addr,EMAIL_DOMAIN);
print_result($valid);

function 
print_result($valid)
{
    echo 
$valid ? ('Thank you.  Valid 'EMAIL_DOMAIN " email address entered.\n")
????: NamePros.com http://www.namepros.com/showthread.php?t=331690
                : (
'Please enter a valid 'EMAIL_DOMAIN " email address\n");
}
?>
The function is only one line. The test code and comments make up most of the post.

The validator is case insensitive, so YAHOO and yahoo and YaHOo .cOm or .COM (etc.) are all valid.

Tested and works
cef is offline  
Old 05-24-2007, 11:08 PM   #3 (permalink)
Account Suspended
Join Date: May 2007
Posts: 21
haiproductions is an unknown quantity at this point
 



Thanks a lot for this wonderful scripts. Actually I was also looking for this script.
haiproductions is offline  
Old 05-24-2007, 11:39 PM   #4 (permalink)
cef
NamePros Regular
Join Date: May 2004
Location: NYC
Posts: 236
cef is a jewel in the roughcef is a jewel in the roughcef is a jewel in the rough
 


Animal Rescue
My pleasure, I had a validator sitting around. Enhancing it was fun. Here's one that has a couple of more features yet (I've been playing ). Examples in the function header, description below.

NOTE: bbcode is inserting some odd spaces in the comment header and examples. The actual function code is fine.

1. The $domain parameter can be an array or a string, so you can provide multiple domains to test for, not just one. Pass a string, only one is tested. Pass an array, the whole list is tested.

2. There is a third parameter, indicating whether the list is an ALLOW list, or a DISALLOW list. If the parameter is TRUE, then the email address MUST be from $domain. If the parameter is FALSE, then the email address MUST NOT be from the domains in the list.

It sounds more complicated than it is. The one-line examples are self-explanatory.

Tested and works.

PHP Code:
<?php

/**************************************************************************
*
* validate_email($email,$domains=null,$allowed=false);
*
* Validate an email address, with an optional allow/disallow domain spec.
*
* Parameters:
*        $email        The FULL email address, e.g. myname@mydomain.com
*        $domains    A single domain or an array of domain names
*        $allowed    If true, $domains contains an array of domain names
*                    or a single domain name from which $email MUST come.  
*                    If false, $domains contains an array of domains
*                    or a single domain from which $email MAY not come.
*
* Returns:
*        true or false as the case may be.
*
* The tests are all case INsensitive.
*
* Examples:
*
*        validate_email($email);                                            any valid email address is allowed
*        validate_email($email,'yahoo.com',true);                        ONLY email from YAHOO.COM addresses allowed
????: NamePros.com http://www.namepros.com/showthread.php?t=331690
*        validate_email($email,'yahoo.com',false);                        yahoo.com email addresses are NOT allowed
*        validate_email($email,array('yahoo.com','gmail.com'),true);        yahoo and gmail ONLY allowed
*        validate_email($email,array('yahoo.com','gmail.com'),false);    yahoo and gmail are DISALLOWED
**************************************************************************/
function validate_email($email,$domains=null,$allowed=false)
{
    
// basic check first for acceptable format
    
if (!preg_match('/^([0-9a-z]+[-._+&])*[0-9a-z]+@([-0-9a-z]+[.])+[a-z]{2,6}$/i',$email)) return false;

    
// domains to process?
    
if ($domains)
    {
        
// a list, so flatten it
        
if (is_array($domains))
????: NamePros.com http://www.namepros.com/showthread.php?t=331690
        {
            
// empty array? bad input, so fail!
            
if (count($domains) == 0) return false;

            
// now we have a regex pattern like domain1|domain2|domain3
            
$domains implode('|',$domains);
        }

        
// now check, regardless of whether original input was a list or a string
        
return !preg_match('/@(' $domains ')$/i',$email) ? !$allowed $allowed;
    }
    else 
        return 
true;
}
?>
cef is offline  
Old 05-25-2007, 07:15 PM   #5 (permalink)
NamePros Regular
 
abdussamad's Avatar
Join Date: Jul 2006
Location: Karachi
Posts: 794
abdussamad is a glorious beacon of lightabdussamad is a glorious beacon of lightabdussamad is a glorious beacon of lightabdussamad is a glorious beacon of lightabdussamad is a glorious beacon of light
 



Impressive stuff. I love the way you've used $allowed in the ternary operator.
abdussamad is offline  
Old 05-26-2007, 02:18 PM   #6 (permalink)
cef
NamePros Regular
Join Date: May 2004
Location: NYC
Posts: 236
cef is a jewel in the roughcef is a jewel in the roughcef is a jewel in the rough
 


Animal Rescue
Thanks

New code below to correct a minor bug: emails ending with things like .co.uk or .co.in failed to validate. That's fixed, as well as a little further streamlining of the code to do only one preg match. NOTE that the last parameter now defaults to TRUE instead of FALSE.

PHP Code:
<?
/**************************************************************************
*
* validate_email($email,$domains=null,$allowed=true)
*
* Validate an email address, with an optional allow/disallow domain spec.
*
* Parameters:
*        $email        The FULL email address, e.g. myname@mydomain.com
*        $domains    A single domain or an array of domain names
????: NamePros.com http://www.namepros.com/showthread.php?t=331690
*        $allowed    If true, $domains contains an array of domain names
*                    or a single domain name from which $email MUST come.  
*                    If false, $domains contains an array of domains
*                    or a single domain from which $email MAY not come.
*
* Returns:
*        true or false as the case may be.
*
* The tests are all case INsensitive.
*
* Examples:
*
*        validate_email($email);                                            any valid email address is allowed
*        validate_email($email,'yahoo.com',true);                        ONLY email from YAHOO.COM addresses allowed
*        validate_email($email,'yahoo.com',false);                        yahoo.com email addresses are NOT allowed
*        validate_email($email,array('yahoo.com','gmail.com'),true);        yahoo and gmail ONLY allowed
*        validate_email($email,array('yahoo.com','gmail.com'),false);    yahoo and gmail are DISALLOWED
**************************************************************************/
function validate_email($email,$domains=null,$allowed=true)
{
    if (
is_array($domains))  // a list, so flatten it
    
{
        
// empty array? default to all domains
        
if (count($domains) == 0)
            
$domains '[-0-9a-z]+[.]+([-0-9a-z]{2,6}+[.]){0,1}[a-z]{2,6}';
        else 
// now we have a regex pattern like domain1|domain2|domain3
            
$domains implode('|',$domains);
    }
    else if (!
$domains)
        
$domains '[-0-9a-z]+[.]+([-0-9a-z]{2,6}+[.]){0,1}[a-z]{2,6}';
????: NamePros.com http://www.namepros.com/showthread.php?t=331690

    
// now check, regardless of whether original input was a list or a string or nothing
    
return !preg_match('/^([0-9a-z]+[-._+&])*[0-9a-z]+@(' $domains ')$/i',$email) ? !$allowed $allowed;
}
?>
cef is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:20 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger