Reply to Re: [PHP] How to ge the ones which are not

Your name:

Reply:


Posted by Richard Lynch on 10/21/49 11:10

> I've built this little regular expression to test wether an e-mail
> address is valid or not:
>
> if(eregi
> ("^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$",
> $email))

First, you should be aware that your RegEx is wrong.

I know it's wrong, because the CORRECT Regex is 3 *PAGES* long in the
camel book.

That said, maybe this will catch *some* invalid email addresses, and not
raise any false positives on valid email addresses...

Though it sure looks to me like it's gonna complain about *MY* email
address, and then I'll never visit your site again.

> print ('valid email)
> else
> print ('Invalid email');
>
> --
>
> ok, now i want to use this in a filling form web page scenario.
> I have this forms with its fields to be filled and when it gets to the
> e-mail address textbox, i want to check if the address is not well formed.
>
> So i did (notice the "!" before the eregi):
>
> if (!eregi
> ("^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$",
> $email))
> { send a warn to the user telling the e-mail address is not correct}
>
> --
>
> Well, if the first block of code works pretty good saying if an address
> is valid or invalid, the second one, when the data from the filled form
> is checked, always says the adress is invalid.
>
> I thought the "!" would adapt the confition to its new scenario, but,
> well... as i've told you, it isn't.
>
> Any ideas of how to solve this, i.e., being the regular expression (and
> it is), what do i have to do to get only the invalid adresses ?
> In short, i only want to trap the invalid ones.

I can't spot what you've done wrong, but everything you believe to be true
about ! and all that seems right to me...

What email addresses are you using for your test cases?

--
Like Music?
http://l-i-e.com/artists.htm

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация