Jump to content

validating email entries....


barbs75

Recommended Posts

Hi Guys,

 

i have an email validation system on my register script, which checks that the email that the user enters is valid, below is the code that i have used, saw this on a tutorial, and it works for missing '@' in the email and other 'junky' character entries

 

  if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
  	if($email){
	$errorarray['email'] = "The email you have entered is not valid, please try again";
}
}

 

However, with this validation, i was able to enter

personsname@hotmail
and hence missing the extension on the end, which is obviously no good!

 

Is there something missing from this code for it to do that? or should i avoid this technique all together and go with the normal longer function seen in php books etc

 

Just wandering as the technique i have used is shorter and if i can use this, then its obviously more efficient!

 

cheers

 

Craig

Link to comment
https://forums.phpfreaks.com/topic/101406-validating-email-entries/
Share on other sites

yeah, I have to admit, i had been using:

 

eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);

 

but recently switched over to:

 

preg_match('/^[-_a-z0-9\'+*$^&%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+@(??![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d++)?$/iD', $email);

 

WORLDS of difference.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.