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 ereg / POSIX question

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

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-10-2006, 02:32 PM THREAD STARTER               #1 (permalink)
NamePros Regular
 
moondog's Avatar
Join Date: Jun 2004
Posts: 587
moondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to all
 



ereg / POSIX question


Trying to do a quick down, dirty, and crude validation of an email address. I have:

PHP Code:
if(ereg('[[:alnum:]]@[[:alnum:]][.][[:alnum:]]'$_POST[email])) { echo "valid email";}
else {echo 
"invalid email";} 
the probem is that is keeps kicking everything out.

If I remove anything after the period (in the domain) like this:

PHP Code:
if(ereg('[[:alnum:]]@[[:alnum:]]'$_POST[email])) { echo "valid email";}
????: NamePros.com http://www.namepros.com/programming/195993-ereg-posix-question.html
else {echo 
"invalid email";} 
it works fine, but I wanted to add the check for the TLD on the domain of the email address. I tried with and without the character class around the period:

PHP Code:
if(ereg('[[:alnum:]]@[[:alnum:]].[[:alnum:]]'$_POST[email])) { echo "valid email";}
????: NamePros.com http://www.namepros.com/showthread.php?t=195993
else {echo 
"invalid email";} 
but it still kicks everything out.

Suggestions?

-Bob
__________________
Can't wait to be out of this forsaken business. Getting close! :)
moondog is offline  
Old 05-10-2006, 03:10 PM   #2 (permalink)
Domains my Dominion
 
sdsinc's Avatar
Join Date: Aug 2005
Location: Web 1.0
Posts: 9,552
sdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatness
 


Third World Education Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Animal Rescue Animal Cruelty AIDS/HIV Animal Rescue Wildlife Breast Cancer Animal Rescue Wildlife
Works fine with me. What E-mail address are you using for testing ?
Are you sure the E-mail is not altered in the POST request ?

Also if you want to get extreme you may want to look into raw RFC822 validation:
http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html
but I think it would be overkill ;-)
__________________
NameNewsletter.com - free lists of available domain names
ZoneFiles.net (beta) - ccTLD and gTLD droplists
sdsinc is offline  
Old 05-10-2006, 03:14 PM   #3 (permalink)
Senior Member
 
Shorty's Avatar
Join Date: Sep 2005
Location: England
Posts: 1,034
Shorty is just really niceShorty is just really niceShorty is just really niceShorty is just really nice
 



Use this instead:
Code:
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})", $_POST['email']))
Shorty is offline  
Old 05-10-2006, 03:39 PM THREAD STARTER               #4 (permalink)
NamePros Regular
 
moondog's Avatar
Join Date: Jun 2004
Posts: 587
moondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to all
 



Thanks shorty.
__________________
Can't wait to be out of this forsaken business. Getting close! :)
moondog is offline  
Old 05-10-2006, 05:57 PM   #5 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Originally Posted by Shorty
Use this instead:
Code:
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})", $_POST['email']))
Thought I'd point out, using:
PHP Code:
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})"$_POST['email'])) 
Would cut out a few extensions

Instead use:
PHP Code:
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})"$_POST['email'])) 
????: NamePros.com http://www.namepros.com/showthread.php?t=195993
Eric is offline  
Old 05-10-2006, 09:40 PM   #6 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
I personally use :-
????: NamePros.com http://www.namepros.com/showthread.php?t=195993

PHP Code:
eregi('^[a-z0-9\._-]+@[a-z0-9\._-]+\.[a-z0-9\.]+$',$email_addy,$dummy
__________________
Manage your portfolio using my new Domain Portfolio Management script.
Securing Your Domain Name From Theft
Peter is offline  
Old 05-11-2006, 10:10 AM THREAD STARTER               #7 (permalink)
NamePros Regular
 
moondog's Avatar
Join Date: Jun 2004
Posts: 587
moondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to all
 



Originally Posted by SecondVersion
Would cut out a few extensions
Ah, yes, Don't want the .COOP, .AERO, and .MUSEUM folks to feel left out.
????: NamePros.com http://www.namepros.com/showthread.php?t=195993

-Bob
__________________
Can't wait to be out of this forsaken business. Getting close! :)
moondog is offline  
Old 05-11-2006, 02:49 PM   #8 (permalink)
NamePros Member
Join Date: Apr 2005
Posts: 117
mikesherov will become famous soon enoughmikesherov will become famous soon enough
 



From PHP.net, if you like overkill:
PHP Code:
<?php
// Completely update for match RFC 2822 and RFC 1035
// http://www.faqs.org/rfcs/rfc2822.html
// http://www.faqs.org/rfcs/rfc1035.html

// Example results:

$email[] = 'foo@example.com';                      // matched
$email[] = 'foo.bar@example.co.uk';                // matched
$email[] = 'foo_bar@example.com';                  // matched
$email[] = '_foo_bar@example.com';                // matched
$email[] = 'foo@example.example';                  // matched
$email[] = '%#a+f.*&654_-._@ee.xx';                // matched
$email[] = 'foo@abc-123.xx';                      // matched
$email[] = 'a@a.a.a.a.aa';                        // matched
$email[] = 'a@a9.aa';                              // matched
$email[] = 'a!b#c$d%e^f&g*h\'i+j-k{l|m}n_/@op.qr'//matched

$email[] = '';                                    //separator

$email[] = 'foo@-example.com';                    // not matched
$email[] = 'foo@example-.com';                    // not matched
$email[] = '%#af.*&@a%#b.xx';                      // not matched
$email[] = 'a@a.99.00.a.aa';                      // not matched
$email[] = '_-._@-.--';                            // not matched
$email[] = 'any..thing@bla.bla';                  // not matched
$email[] = '@.';                                  // not matched
$email[] = '@.com';                                // not matched
$email[] = '@exam@exam.com';                      // not matched
$email[] = ' @ .com';                              // not matched
$email[] = '.bar@example.com';                    // not matched
$email[] = 'foo.@example.com';                    // not matched
$email[] = 'foo@example.x';                        // not matched
????: NamePros.com http://www.namepros.com/showthread.php?t=195993

$atom '[-a-z0-9!#$%&\'*+/=?^_`{|}~]';    // allowed characters for part before "at" character
$domain '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'// allowed characters for part after "at" character

$regex '^' $atom '+' .        // One or more atom characters.
'(\.' $atom '+)*'.              // Followed by zero or more dot separated sets of one or more atom characters.
????: NamePros.com http://www.namepros.com/showthread.php?t=195993
'@'.                                // Followed by an "at" character.
'(' $domain '{1,63}\.)+'.        // Followed by one or max 63 domain characters (dot separated).
$domain '{2,63}'.                  // Must be followed by one set consisting a period of two
'$';                                // or max 63 domain characters.

foreach ($email as $example) {
   if (
strlen($example) == 0):
       echo 
'&nbsp;<br>';
   else:
     if (
eregi($regex$example)):
       echo 
$example ' matched<br>';
     else:
       echo 
'<strong>'$example ' not matched</strong><br>';
     endif;
   endif;
}
?>
mikesherov is offline  
Closed Thread


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


Liquid Web Smart Servers  
All times are GMT -7. The time now is 07:01 PM.

Managed Web Hosting by Liquid Web
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