Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Server Side Programming
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 10-16-2009, 01:15 AM
  #1
Sawtooth500
Lord (Level 16)
 
Sawtooth500's Avatar
 
Join Date: Nov 2007
Location: Chicago, IL. USA
Posts: 606
iTrader: (0)
Sawtooth500 is on a distinguished road
Need regex help (again lol)

Thank you for the help, my regex sucks...

So I've got this nifty and robust function that works GREAT for validating emails. The problem is it uses ereg, which goes bye bye with PHP 6. So I need to convert it to preg, I'd appreciate your help!

PHP Code:
function check_email_address($email) {
    
// First, we check that there's one @ symbol, and that the lengths are right
    
if (!ereg("^[^@]{1,64}@[^@]{1,255}$"$email)) {
        
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
        
return false;
    }
    
// Split it into sections to make life easier
    
$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])) { // Check if domain is IP. If not, it should be valid domain name
        
$domain_array explode("."$email_array[1]);
        if (
sizeof($domain_array) < 2) {
                return 
false// Not enough parts to domain
        
}
        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;

__________________
-Taras Hryniw

http://www.waltonstreetwebdesign.com
Sawtooth500 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-18-2009, 09:42 PM
  #2
blackpepper
Gampi
 
blackpepper's Avatar
 
Join Date: Jul 2005
Location: metro - nyc
Posts: 1,282
iTrader: (0)
blackpepper will become famous soon enough
Iv been doing work on a script which requires email addresses to be validated as well. One things which I cam across which may be useful to you is the filter_var
i.e
PHP Code:
if(filter_var($emailFILTER_VALIDATE_EMAIL)) {
    echo 
"$email - Valid Address";

which can be useful for looping through an array of emails
__________________
blackpepper is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Reply
KEEP TABS
SPONSORS
 
Boxedart

 
 


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



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 02:51 AM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.