You are here: Re: heads or tails of email address parser « PHP Programming Language « IT news, forums, messages
Re: heads or tails of email address parser

Posted by Richard Cornford on 02/18/07 13:04

pcx99 wrote:
> -Lost wrote:
>> chadlupkes wrote:
<snip>
>>> <?if(preg_match("/MSIE 5.0;/", $_SERVER['HTTP_USER_AGENT']))
>>> // this is IE 5.0
>>> {?>
<snip>
>> I swear this looks like PHP and JavaScript.
<snip>
> You swear right! It sends one block of code to the browser
> if the client is MSIE version 5 and another for all other
> versions.

It sends one block of code if the User Agent header contains the
character sequence "MSIE 5.0" and the other if it does not. That has
nothing to do with whether the browser is IE 5 or not, as the User Agent
header is not specified as being a source of information and many
browsers are known to spoof IE's UA headers (and so some will spoof IE 5
directly, or include the character sequence "MSIE 5.0").

> Probably to work around some bug or another in IE.

It is an irrational attempt to compensate for the level of regular
expression support. It suffers from assuming non-standard regular
expression syntax is available in all browsers that are not IE 5 (or
spoofing IE 5 in some way).

<snip>
> This script will need to be placed on a server with php to work
> properly. It can be altered to function without the need for php.
>
>
> function parseemail(str) {
> str = trim(str);
> if (navigator.userAgent.indexOf('MSIE 5.0')>0) {
^^
For equivalence with the irrational PHP above that should be; greater or
equal to 0, or greater than -1.

> if(str.search(/\w+@[\w\W]+\.[a-z]{3}/) == -1) {
> window.alert("Please enter a valid email address");
> return true;
> } else {
> if(str.search(/^[\w\-\.]+[@][\w\-]+(?:\.[\w\-]+)+$/) == -1) {
> window.alert("Please enter a valid email address");
> return true;
> }
> }
> }
>}
>
> I didn't test the function so it will probably implode, or
> explode but at least it gets a little closer to being liked
> by explorer.
<snip>

The User Agent header (and so the navigator.userAgent string) is not
specified as being a source of information, and so should not be used as
one. There is no relationship, real or implied, between the contents of a
User Agent header and the level of regular expression support on a
browser. Regular expression support in JScript is independent of the
browser version. If the first regular expression is ever acceptable there
is no reason why it should not always be acceptable. Neither regular
expression seems to be a discriminator of a "valid email address" (though
the first is much worse than the second).

A bad idea moved from PHP to the client is not a step forward.

Richard.

 

Navigation:

[Reply to this 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

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