473,322 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

heads or tails of email address parser

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;
}
<?}?>
}

Feb 18 '07 #1
9 1503
"chadlupkes" <ch********@gmail.comwrote in message
news:11**********************@q2g2000cwa.googlegro ups.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
Feb 18 '07 #2
-Lost wrote:
"chadlupkes" <ch********@gmail.comwrote in message
news:11**********************@q2g2000cwa.googlegro ups.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
Feb 18 '07 #3
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ö
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Feb 18 '07 #4
"Kimmo Laine" <sp**@outolempi.netwrote in message
news:er**********@nyytiset.pp.htv.fi...
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
I am horrible at Finnish and the best translation I got is something about a "sinister
man" and an "apple."

What is the literal translation in English, preferably, please.

-Lost
Feb 18 '07 #5
-Lost kirjoitti:
"Kimmo Laine" <sp**@outolempi.netwrote in message
news:er**********@nyytiset.pp.htv.fi...
>"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö

I am horrible at Finnish and the best translation I got is something about a "sinister
man" and an "apple."

What is the literal translation in English, preferably, please.
"En ole paha ihminen, mutta omenat ovat elinkeinoni." =
"I am not a bad person, but apples are my trade."

And the explanation to where this expression originates and why I
consider it funny is rather lengthy, short version: it was said by a
Finnish Big Brother 2005 contestant Perttu.

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Feb 18 '07 #6
Kimmo Laine wrote:
chadlupkes kirjoitti:
<snip>
>str = trim(str);

Trims whitespace from the input
Assuming a congaing scope defines a function called - trim - and trimming
white space is what that function does (likely but not certain).
><?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:
Not 'if the user agent is' but 'if the user agent header contains the
character sequence'.

<snip>
A complete rewrite couldn't make it worse.
It is irrational as it is.
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,
They re not. The standard for the language provides a minimum syntax for
regular expressions, and then allows implementations to extend it. You
achieve cross-browser compatibility by using the specified syntax and
keep the extensions for use only when you know the browser environment
with certainty. (that just leaves one or two very minor bugs to be
avoided).
but then again with IE nothing suprises me.
In this context any fault to be attributed goes to the author of the
code. IE is innocent here.

Richard.

Feb 18 '07 #7
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.

Feb 18 '07 #8
Good discussion.

There are a few other options for validating an email address that
I've found. Here are some links:

http://www.smartwebby.com/DHTML/email_validation.asp

http://www.4guysfromrolla.com/webtech/091998-1.shtml

http://homepage.ntlworld.com/kayseycarvey/jss3p7.html

http://javascript.about.com/od/compl...ts/a/email.htm

http://www.w3schools.com/js/js_form_validation.asp

And there's more:

http://www.google.com/search?hl=en&q...ess+javascript

Thanks for the input! I think I'll go with something a little more
mainstream.

Chad

On Feb 18, 5:04 am, "Richard Cornford" <Rich...@litotes.demon.co.uk>
wrote:
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.
Feb 18 '07 #9
In comp.lang.javascript message <11**********************@q2g2000cwa.goo
glegroups.com>, Sat, 17 Feb 2007 22:11:21, chadlupkes
<ch********@gmail.composted:
>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?
The best thing you can do with that code is to sort the characters into
"alphabetical" order for re-use elsewhere.

See <URL:http://www.merlyn.demon.co.uk/js-valid.htm>

It's a good idea to read the newsgroup and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Feb 19 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dan Williams | last post by:
Apologies for the cross-post but i thought i'd aim for the largest audience possible. I have a web site that users have to register to with their email address. The site then emails the user...
8
by: pcchong | last post by:
what is the simplest way to put the email address on the homepage so that it is not readable by email extractor or search engine? I remember someone wrote a simple script to do that, but I can't...
117
by: Steevo | last post by:
Any suggestions as to the best programs for cloaking email addresses? Many thanks -- Steevo
4
by: Tom Warren | last post by:
About once a year or so for the last 10 years, I update my street address parser and I'm starting to look at it again. This parser splits a street address line into its smallest common elements...
3
by: scott_baird | last post by:
I have an email macro setup (maybe I should go another way, but that was the quickest at the moment...) and what I would like to do is automate the "to" addressee of the email it generates for...
5
by: Michael C# | last post by:
Hi all, I'm about to start writing a routine to parse "standard" U.S. Addresses (if there is such a thing...) Before I jump off into this, I was just wondering if maybe someone out there had...
0
by: comp.lang.php | last post by:
I wrote a method that should check if an email address is valid. In another method I've already checked to see if $_POST exists and is well-formed, so those checks are not necessary in this scope....
9
by: chadlupkes | last post by:
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...
4
by: lishengs | last post by:
HI all, Any email message parser wrote in C available? Thanks in advance.
1
by: saravanatmm | last post by:
I need javascript code for validate the email address. Email address field cannot allowed the capital letters, special characters except '@' symbol. But can allowed the small letters, numeric...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.