xyn Posted June 29, 2006 Share Posted June 29, 2006 HiiDoes anyone know how to make my code correct so an e-mail MUST be filled in correctly:[code]$email = $_POST['mail'];if( !preg_match("/[A-Za-z0-9\._%-]+\@[A-Za-z0-9\._%-]+/", $email)){die('error');}[/code] Link to comment https://forums.phpfreaks.com/topic/13208-preg_match/ Share on other sites More sharing options...
Buyocat Posted June 29, 2006 Share Posted June 29, 2006 I suggest looking into the PEAR package, Validator - or something like that. I use it to verify emails and it works like a charm. Even if you don't want the extra code, it is worth checking out to see what regular expression they use. Link to comment https://forums.phpfreaks.com/topic/13208-preg_match/#findComment-50835 Share on other sites More sharing options...
xyn Posted June 29, 2006 Author Share Posted June 29, 2006 [!--quoteo(post=389268:date=Jun 29 2006, 03:42 PM:name=Buyocat)--][div class=\'quotetop\']QUOTE(Buyocat @ Jun 29 2006, 03:42 PM) [snapback]389268[/snapback][/div][div class=\'quotemain\'][!--quotec--]I suggest looking into the PEAR package, Validator - or something like that. I use it to verify emails and it works like a charm. Even if you don't want the extra code, it is worth checking out to see what regular expression they use.[/quote]I took a 2nd glance and realised i forgotte to put the .com // .co.uk etc. part so it should have looked like:[code]$mail = $_POST['mail'];if( !preg_match("/[A-Za-z0-9\._%-]+\@[A-Za-z0-9\._%-]+.[A-Za-z0-9\]/", $mail)){die('error: no email');}[/code] Link to comment https://forums.phpfreaks.com/topic/13208-preg_match/#findComment-50841 Share on other sites More sharing options...
obsidian Posted June 29, 2006 Share Posted June 29, 2006 [!--quoteo(post=389274:date=Jun 29 2006, 10:50 AM:name=Ashh)--][div class=\'quotetop\']QUOTE(Ashh @ Jun 29 2006, 10:50 AM) [snapback]389274[/snapback][/div][div class=\'quotemain\'][!--quotec--]I took a 2nd glance and realised i forgotte to put the .com // .co.uk etc. part so it should have looked like:[code]$mail = $_POST['mail'];if( !preg_match("/[A-Za-z0-9\._%-]+\@[A-Za-z0-9\._%-]+.[A-Za-z0-9\]/", $mail)){die('error: no email');}[/code][/quote]about the best email validation i've found is this:[code]preg_match('|^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$|i', $email);[/code]the only things you're really missing is the '^' at the beginning and the '$' at the end to make sure that nothing funky has been going on in front or behind it. Link to comment https://forums.phpfreaks.com/topic/13208-preg_match/#findComment-50861 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.