indexOf does not work?

J

Jenny

Hi All,

I have this code. When I type in (e-mail address removed), it should run
alert("Thanks for your interest.") line. But it does not. Why and
how can I correct it? I use IE 6 with windows xp.
Thanks a lot.

<HTML><body>
<form name="myForm">
<INPUT TYPE="text" VALUE="Enter email" NAME="userEmail"
onChange=validateInput()>
</form>
<script type="text/javascript">
this.myForm.userEmail.select()
function validateInput() {
userInput = this.myForm.userEmail.value
document.write(userInput)
if (userInput.indexOf('@')>0 && userInput.indexOf('.')>0)
alert("Thanks for your interest.")
else
alert("Please check that your email details are correct before
submitting")
}
</script>
 
L

Lee

Jenny said:
Hi All,

I have this code. When I type in (e-mail address removed), it should run
alert("Thanks for your interest.") line. But it does not. Why and
how can I correct it? I use IE 6 with windows xp.
Thanks a lot.

<HTML><body>
<form name="myForm">
<INPUT TYPE="text" VALUE="Enter email" NAME="userEmail"
onChange=validateInput()>
</form>
<script type="text/javascript">
this.myForm.userEmail.select()
function validateInput() {
userInput = this.myForm.userEmail.value
document.write(userInput)

At this point, you've re-opened the current document and
written new HTML into it. Any previously existing HTML
or Javascript code in this page has been destroyed.
Any code that expects to interact with the previous HTML
or Javascript will fail.
 
J

Jeff North

On 25 Sep 2004 22:25:02 -0700, in comp.lang.javascript
| Hi All,
|
| I have this code. When I type in (e-mail address removed), it should run
| alert("Thanks for your interest.") line. But it does not. Why and
| how can I correct it? I use IE 6 with windows xp.
| Thanks a lot.
|
| <HTML><body>
| <form name="myForm">
| <INPUT TYPE="text" VALUE="Enter email" NAME="userEmail"
| onChange=validateInput()>
| </form>
| <script type="text/javascript">
| this.myForm.userEmail.select()
| function validateInput() {
| userInput = this.myForm.userEmail.value
| document.write(userInput)

Replace the above line with alert( userInput );
 
D

Dr John Stockton

JRS: In article <[email protected]
et>, dated Sun, 26 Sep 2004 17:16:19, seen in
Robert said:
There are more complete tests to verify an email address if you are
interested.

See:
http://www.webreference.com/js/tips/990928.html

It is *not* possible to verify an e-mail address -
<URL:http://www.merlyn.demon.co.uk/js-valid.htm#VEmA> ;
indeed , thanks for the reminder, I have just changed the set of
addresses valid here, while not connected to the Internet.

One can only check that the format is compliant with the RFCs, which is
enough, in general, enough to show that an E-address has been attempted.
 
G

Grant Wagner

Jim said:
But please don't use that one, as it rejects completely valid email
addresses.

And allows invalid E-mail addresses. Her test says: " .@" is a valid
E-mail address.
 
R

Robert

[email protected] (Jim Ley) wrote in message news: said:
But please don't use that one, as it rejects completely valid email
addresses.

Does someone have one to recommend?

I am looking for one that will exclude invalid characters too. Might
as well get as in as much validation as possible.

Robert
 
J

Jim Ley

Does someone have one to recommend?

No, it's not worth the effort, the risk of losing a sale because you
reject a valid email address you don't understand isn't worth the
effort.

The cost of having lots of (e-mail address removed), or (e-mail address removed)
etc is higher than having an email address - people don't type in
invalid email addresses unless they're also going to type invalid but
syntactically correct if forced to.

Jim.
 
M

Matt Kruse

Jim said:
No, it's not worth the effort, the risk of losing a sale because you
reject a valid email address you don't understand isn't worth the
effort.

I think this is worrying too much about a situation that will never happen.

If someone goes to a web form to get information or buy a product and enters
an email address with nested comments, etc, then they're just being an ass.
In all my years of seeing forms submitted, I've never (that I can think of)
seen a valid email address from a person genuinely trying to submit the form
that wouldn't pass some simple validation tests.

I have seen my forms without any validation get submitted with values like
(e-mail address removed) or (e-mail address removed) etc. Simple javascript validation would
prevent typos like that.
people don't type in
invalid email addresses unless they're also going to type invalid but
syntactically correct if forced to.

This is true. You can't prevent invalid but syntactically correct emails
from being submitted, and you shouldn't even think about trying :)
 
J

Jim Ley

I think this is worrying too much about a situation that will never happen.

Businesses have lost many thousands of pounds worth of sales because
they reject (e-mail address removed) - I'm not alone in this. (if
it's the only place I can buy the product then I'll carry on, if not,
and there's generally lots of places at the same price, then I'll buy
it elsewhere)
If someone goes to a web form to get information or buy a product and enters
an email address with nested comments, etc, then they're just being an ass.

Oh yeah, nested comments is an ass - rejecting an email address
because it's got a + in it (which gmail is popularising right now) or
because they have a .info or .museum TLD (which many block as they
have 2,3 at the end) and most of the popular examples do break on
these.

Jim.
 
R

Robert

No, it's not worth the effort, the risk of losing a sale because you
reject a valid email address you don't understand isn't worth the
effort.

The cost of having lots of (e-mail address removed), or (e-mail address removed)
etc is higher than having an email address - people don't type in
invalid email addresses unless they're also going to type invalid but
syntactically correct if forced to.

Maybe a simple test is best. I did get a few email address like
thomas129. I had to guess the id was from AOL.

Javascript form validation - doing it right by Stephen Poley
http://www.xs4all.nl/~sbpoley/webmatters/formval.html#update

Stephen suggests a warning level and an error level. Seems like a
good idea.


I found the link on Dr J R Stockton page.

Robert
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Wed, 29
Sep 2004 08:59:36, seen in Jim Ley
No, it's not worth the effort, the risk of losing a sale because you
reject a valid email address you don't understand isn't worth the
effort.

IMHO, it is worth validating with /.+@.+\..+/ - something AT something
DOT something, to ensure that an Internet-style E-mail address is
present, as opposed to <empty> or some other data.

It might also be worth checking that all characters are legal, since
that might help a bad typist.

A good implementation will allow commented E-mail addresses; there are
those who use something like (e-mail address removed) , so it can
be really useful to insert Fred <[email protected]> in
the field, if it will be honoured for a return message. There may be
no very good implementations in use; but the RegExp above should allow
it.

If that RegExp is used, or, rather, /<?(\S+@\S+\.\S+)>?/ , then it
is that recognised part - RegExp.$1 or whatever is more compatible, that
may be tested for improper characters. More thought is needed if there
is to be a check that any comment is RFC-compliant. E&OE.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top