473,800 Members | 2,529 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_AGEN T'])) // this
is IE 5.0
{?>
if(str.search(/\w+@[\w\W]+\.[a-z]{3}/) == -1)
{
window.alert("P lease 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("P lease enter a valid email address");
return true;
}
<?}?>
}

Feb 18 '07 #1
9 1899
"chadlupkes " <ch********@gma il.comwrote in message
news:11******** **************@ q2g2000cwa.goog legroups.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_AGEN T'])) // this
is IE 5.0
{?>
if(str.search(/\w+@[\w\W]+\.[a-z]{3}/) == -1)
{
window.alert("P lease 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("P lease enter a valid email address");
return true;
}
<?}?>
}
I swear this looks like PHP and JavaScript.

-Lost
Feb 18 '07 #2
-Lost wrote:
"chadlupkes " <ch********@gma il.comwrote in message
news:11******** **************@ q2g2000cwa.goog legroups.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_matc h("/MSIE 5.0;/", $_SERVER['HTTP_USER_AGEN T'])) // this
is IE 5.0
{?>
if(str.searc h(/\w+@[\w\W]+\.[a-z]{3}/) == -1)
{
window.alert(" Please enter a valid email address");
return true;
}
<?}else{ // not IE 5.0
?>
if(str.searc h(/^[\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.user Agent.indexOf(' MSIE 5.0')>0) {
if(str.search(/\w+@[\w\W]+\.[a-z]{3}/) == -1) {
window.alert("P lease enter a valid email address");
return true;
} else {
if(str.search(/^[\w\-\.]+[@][\w\-]+(?:\.[\w\-]+)+$/) == -1) {
window.alert("P lease 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_AGEN T'])) // 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("P lease 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("P lease 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***@bhg byrzcv.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***@bhg byrzcv.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_matc h("/MSIE 5.0;/", $_SERVER['HTTP_USER_AGEN T']))
// 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_mat ch("/MSIE 5.0;/", $_SERVER['HTTP_USER_AGEN T']))
// 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.user Agent.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("P lease enter a valid email address");
return true;
} else {
if(str.search(/^[\w\-\.]+[@][\w\-]+(?:\.[\w\-]+)+$/) == -1) {
window.alert("P lease 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.userA gent 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...@litote s.demon.co.uk>
wrote:
pcx99 wrote:
-Lost wrote:
chadlupkes wrote:
<snip>
><?if(preg_matc h("/MSIE 5.0;/", $_SERVER['HTTP_USER_AGEN T']))
// 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.user Agent.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("P lease enter a valid email address");
return true;
} else {
if(str.search(/^[\w\-\.]+[@][\w\-]+(?:\.[\w\-]+)+$/) == -1) {
window.alert("P lease 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.userA gent 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.javas cript message <11************ **********@q2g2 000cwa.goo
glegroups.com>, Sat, 17 Feb 2007 22:11:21, chadlupkes
<ch********@gma il.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
"alphabetic al" order for re-use elsewhere.

See <URL:http://www.merlyn.demo n.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.c om/faq/index.html>.
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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

1
3739
by: Thomas Williams | last post by:
Thanks, I tried it and it stop at: f = file("mail.txt") with the error message. TypeError: 'str' object is not callable Tom Williams
4
3735
by: Paul Schmidt | last post by:
Dear list: I am new to python, and I am trying to figure out the short answer on something. I want to open a POP3 mailbox, read the enclosed mail using the POP3 module, , and then process it using the email module. Environment Python 2.3.4, Mandrake Linux 9.0 patched up the wazoo...
1
3640
by: Nils M. Lunde | last post by:
Hi! I'm trying to do the following: -Extract an Email from a mailbox using grepmail -Bounce this Email to a different address I thought that this would be an easy thing to do, but I still haven't manage to do it the way I want to.
0
1070
by: Andrey Smirnov | last post by:
I am getting the following traceback after upgrading my app to Python 2.4.1. It's telling me that there is an error in Parser.py. It tells me that 'fp.read(8192)' is given 2 arguments, but it is clearly not true. Does anybody know what's going on here? Traceback (most recent call last): File "/opt/etext/lib/python2.4/site-packages/etext/enqueue.py", line 252, in work worker(e.linkval, info) File "/opt/etext/bin/etreceive", line 30,...
4
5524
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 (number, trailer, pre, name, suffix, post, unit, unit id). I always start this update process by searching Google-Groups and Google-web for anything new out there, but there is never very much. Has anyone run into anything in their travels?...
11
308
by: Ron Vecchi | last post by:
I've used System.Web.Mail before but have never had the need to send attchemnets through it...until now. A client of mine would like a form on the website to allow a user to type up a message and upload a file. I'm staying away from mailto links. So the file and message will be uploaded to the server when the user clicks send. The new file and message will be processed and emailed from the server to my client. I'm tring to get any...
17
2170
by: HornyLaBelle | last post by:
I'm hiding the email address on a website with this javascript which works fine: --------------------------------- <p>Send your comments and questions to our <script language=javascript> <!-- var contact = "Newsletter Editor"
7
10861
by: Beefminator | last post by:
Hello, How can you create a hyperlink in the HTML body of CDOsys email? Line 7 is a link for yahoo.com, but the asp page does not work. Set objMessage = CreateObject("CDO.Message") objMessage.Subject ="Test Page - File upload" objMessage.Sender = "" & Request.Form("email1") & "" objMessage.To ="jason@yahoo.com" objMessage.HTMLBody = "Email: " & Request.Form("email1") & vbCrLf & _
9
1522
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 valid form */ function parseemail(str) { str = trim(str); <?if(preg_match("/MSIE 5.0;/", $_SERVER)) // this is IE 5.0
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10251
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.