Jump to content

Preg_match


xyn

Recommended Posts

[!--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

[!--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

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.