NYCPHP Meetup

NYPHP.org

[nycphp-talk] Validating Email Addresses

drydell at att.net drydell at att.net
Thu Dec 2 13:50:44 EST 2004


a problem here is that a valid email address like firstname.lastname at domain.com would be rejected...

 -------------- Original message ----------------------
From: Rahmin Pavlovic <rahmin at insite-out.com>
> I wrote this a while back, as I'm somewhat illiterate when it comes to regexp's:
> 
> function is_email($str) {
> 	$str=trim($str);
> 	if($str=='') { return false; }
> 	if(strstr($str,'@')=='' || strstr($str,'.')=='') { return false; }
> 	if(strpos($str,'@') > strrpos($str,'.')) { return false; }
> 	if(strpos($str,'@') < 1) { return false; }
> 	if((strrpos($str,'.') - strpos($str,'@')) < 3) { return false; }
> 	if((strlen($str) - strrpos($str,'.')) < 3) { return false; }
> 	return true;
> }
> 
> It's slightly liberal, but does force input to x at xx.xx.  That should would work 
> for cases like Joe <joe at bob.com>.
> 
> HTH
> 
> 
> _______________________________________________
> New York PHP Talk
> Supporting AMP Technology (Apache/MySQL/PHP)
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.newyorkphp.org





More information about the talk mailing list