|
Posted by Kimmo Laine on 02/18/07 07:22
chadlupkes kirjoitti:
> I have this code from someone else, and I'm trying to make heads or
> tails of it because IE doesn't like it. Can anyone help? Or does
> anyone have a better idea?
Starts with a javascript function definition:
> /* parse the email to check for valid form */
> function parseemail(str)
> {
> str = trim(str);
Trims whitespace from the input
> <?if(preg_match("/MSIE 5.0;/", $_SERVER['HTTP_USER_AGENT'])) // this
> is IE 5.0
> {?>
Enter php. If the useragent is IE 5 it prints this block of js:
> if(str.search(/\w+@[\w\W]+\.[a-z]{3}/) == -1)
> {
If the reg exp doesn't match, the js pops an alertbox.
> window.alert("Please enter a valid email address");
> return true;
> }
> <?}else{ // not IE 5.0
> ?>
It's not IE, so it prints this js:
> if(str.search(/^[\w\-\.]+[@][\w\-]+(?:\.[\w\-]+)+$/) == -1) // ||
> str.search(/.+?\@([\w.-]+?\s)/) == -1)
> {
> window.alert("Please enter a valid email address");
> return true;
> }
Both blocks apparently try to validate an email address with a
half-assed regular expression. The first one in particular assumes that
all domains are in format of domain.xyz where the xyz is exactly three
letters, no more or less, this is quite wrong assumption.
something.co.uk, something.fi and something.info might all be valid
domains but do not pass the test.
> <?}?>
> }
>
A complete rewrite couldn't make it worse. I find it difficult to
believe that the javascript engines on different browsers would be so
horribly iincomptaible that you'd need to write a separate regexp for
it, but then again with IE nothing suprises me.
--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)
Navigation:
[Reply to this message]
|