barbs75 Posted April 16, 2008 Share Posted April 16, 2008 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 More sharing options...
ucffool Posted April 17, 2008 Share Posted April 17, 2008 This may help: http://fightingforalostcause.net/misc/2006/compare-email-regex.php Link to comment https://forums.phpfreaks.com/topic/101406-validating-email-entries/#findComment-520001 Share on other sites More sharing options...
bruack Posted April 18, 2008 Share Posted April 18, 2008 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. Link to comment https://forums.phpfreaks.com/topic/101406-validating-email-entries/#findComment-520065 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.