Reply to Re: heads or tails of email address parser

Your name:

Reply:


Posted by pcx99 on 02/18/07 07:08

-Lost wrote:
> "chadlupkes" <chadlupkes@gmail.com> wrote in message
> news:1171779081.479141.299610@q2g2000cwa.googlegroups.com...
>> 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?
>>
>> /* parse the email to check for valid form */
>> function parseemail(str)
>> {
>> str = trim(str);
>> <?if(preg_match("/MSIE 5.0;/", $_SERVER['HTTP_USER_AGENT'])) // this
>> is IE 5.0
>> {?>
>> if(str.search(/\w+@[\w\W]+\.[a-z]{3}/) == -1)
>> {
>> window.alert("Please enter a valid email address");
>> return true;
>> }
>> <?}else{ // not IE 5.0
>> ?>
>> if(str.search(/^[\w\-\.]+[@][\w\-]+(?:\.[\w\-]+)+$/) == -1) // ||
>> str.search(/.+?\@([\w.-]+?\s)/) == -1)
>> {
>> window.alert("Please enter a valid email address");
>> return true;
>> }
>> <?}?>
>> }
>
> I swear this looks like PHP and JavaScript.
>
> -Lost
>


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. Probably
to work around some bug or another in IE. In short, php writing
javascript, one of my favorite things about net programming. It doesn't
go quite as far as php writing javascript writing html creating styles
with a little dynamically created javascript through an eval or two but
it's still pretty fun.

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) {
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.


--
http://www.hunlock.com -- Musings in Javascript, CSS.
$FA

[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

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