help making a better email check

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

help making a better email check

Post by m3rajk »

current: preg_match('/^[\w\.\-]+@[\w\.\-]+\.\w\w\w?$/', $email)

a friend typoed nrt for net. so i figure even with two feilds ineed a better check. i want to allow the two letter country codes and all the 3/4 letter domains (i don't see anyone using museum)
does anyone know a place that has an up to date list? will the others with prel reg exp skim this quickly and make sure i didn't screw up (i find that i have a tendency to make minor mistakes, if i did it should be caught by one of you i expect... don't have a way to test this until i can get a friend to try it, which might be after you look at it)

new: preg_match('/^[\w\.\-]+@[\w\.\-]+\.(\w\w|biz|com|org|gov|net|info)$/', $email)
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

There are LOADS (and I mean LOADS) of domain extensions in the world (one for each country + others).

Off the top of my head you could add .co.uk - .uk.com - .jp - .de - and so on.

Check out http://www.alldomains.com/alltlds.html for a full list but prepare yourself for a shock.

And also don't presume that someone won't use a certain domain name... if it exists then someone somewhere will be using it ;)
mwong
Forum Commoner
Posts: 34
Joined: Sun Dec 28, 2003 2:58 am

Post by mwong »

I always thought that email verification by sending an email and have them verify through that email is best. If they give you a fake email address, well then they won't get the verification email...so they can't get register with you...or whatever
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

mwong: that's what this is for, but certain ones are more obvious than others. this is before checking that it's fake... making sure that the address MIGHT be valid. the way i had it a friend mistyped net nrt and it went through the email catch. the only other thing i can think of to do is to have the join send an email for confirmatiln and then when you confirm that it goes into asking for what i need to go farther... might just do that...


genik: this is just to check the top level is valid.i forgot mil and the ontly one not listed here i had was edu. looks like there's more to add... and i think i'll split joining to two scripts. one to agree to the terms and get the mail sent, one to actually join once that's been verified... still wont hurt to check on the top levels
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

I always tend to use this:

Code: Select all

<?php
ereg("^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", $email);
?>
Then send them an email just to make sure they recieve it and prove that they own the given email address. Guess you could also do a few checks on the domain name before you send the mail to ensure that its valid and in use.
Post Reply