eregi help please

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
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

eregi help please

Post by lostboy »

i have the following code trying to validate an email address...

Code: Select all

if ((strlen($email)>=5)&&(strlen($email)<50))&#123;   //min length 5 and max length 50
        if ((!eregi("^&#1111;www]&#123;3&#125;",$email))||(!eregi("\@setroPETS\.com$",$email)))&#123;
        //the above denies emails starts with 'www' or denies emails with endings 'setroPETS.com'
        //to prevent useless emails from being entered
             if (!eregi("(&#1111;A-Za-z0-9])&#123;4,15&#125;$", $email))&#123;    //prevent emails with 'aaaaaa' or '888888'

                if (eregi("^&#1111;a-zA-Z0-9\.\_]+@&#1111;a-zA-Z0-9]+\.&#1111;a-zA-Z0-9\.]&#123;2,4&#125;$", $email))&#123;
The problem is in the line that is trying to check for emails starting with 'www'. I am trying to prevent emails with www in the username and ones with the domain name 'setropets.com' to prevent useless email addresses from clodding the db?

Currently it does allow something like http://www.bob@bob.com and bob@setropets.com

any ideas as to what i got wrong?
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

I think you are missunderstanding the posix-regex syntax a bit, ([A-z]){2,5} doesn't match 2 to 5 equal characters.. Anyway, I would highly recommend not using posix (ereg), instead use perl regex, it is a lot more efficient.. and When looking for specific text (like www), use str-functions instead.

A full regex for validating all possibilities of an email address is huge, but one that should work for 99% could be something like (untested)

if (preg_match(
'/^[A-z0-9][A-z0-9\\-._]+@[A-z0-9][A-z0-9\\-]+(\\.[A-z0-9][A-z0-9\\-]+)*?\\.[A-z][A-z]+$/',$email)) {
# email address is ok..
}

to find any occurence of 'www'
if (stristr($email,'www')) { /* found www */ }
use the same for matching other strings like domain names etc

what method is most efficient for finding repeated chars I don't know really, perhaps someone else has a good idea on that?

maybe something like
preg_match('([A-z])\\1{3,100}')
i think would match 4 to 100 equeal characters..
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post by daven »

For general email formatting: the email functions at killersoft (http://www.killersoft.com/downloads/paf ... egory&id=1) are great. They check for legal email names/formats. I highly suggest using them.
Post Reply