473,320 Members | 2,052 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,320 software developers and data experts.

indexOf does not work?

Hi All,

I have this code. When I type in je***@ebay.com, 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>
Jul 23 '05 #1
13 1955
On 25 Sep 2004 22:25:02 -0700, in comp.lang.javascript
je************@hotmail.com (Jenny) wrote:
| Hi All,
|
| I have this code. When I type in je***@ebay.com, 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 );
| 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>


---------------------------------------------------------------
jn****@yourpantsbigpond.net.au : Remove your pants to reply
---------------------------------------------------------------
Jul 23 '05 #2
Lee
Jenny said:

Hi All,

I have this code. When I type in je***@ebay.com, 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.

Jul 23 '05 #3
In article <88*************************@posting.google.com> ,
je************@hotmail.com (Jenny) wrote:
if (userInput.indexOf('@')>0 && userInput.indexOf('.')>0)


There are more complete tests to verify an email address if you are
interested.

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

Robert
Jul 23 '05 #4
On Sun, 26 Sep 2004 17:16:19 GMT, Robert <rc*******@my-deja.com>
wrote:
In article <88*************************@posting.google.com> ,
je************@hotmail.com (Jenny) wrote:
if (userInput.indexOf('@')>0 && userInput.indexOf('.')>0)


There are more complete tests to verify an email address if you are
interested.

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


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

Jim.
Jul 23 '05 #5
JRS: In article <rc*****************************@news1.west.earthl ink.n
et>, dated Sun, 26 Sep 2004 17:16:19, seen in news:comp.lang.javascript,
Robert <rc*******@my-deja.com> posted :
In article <88*************************@posting.google.com> ,
je************@hotmail.com (Jenny) wrote:
if (userInput.indexOf('@')>0 && userInput.indexOf('.')>0)


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.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #6
Jim Ley wrote:
On Sun, 26 Sep 2004 17:16:19 GMT, Robert <rc*******@my-deja.com>
wrote:
In article <88*************************@posting.google.com> ,
je************@hotmail.com (Jenny) wrote:
if (userInput.indexOf('@')>0 && userInput.indexOf('.')>0)


There are more complete tests to verify an email address if you are
interested.

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


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.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #7
ji*@jibbering.com (Jim Ley) wrote in message news:<41**************@news.individual.net>...
http://www.webreference.com/js/tips/990928.html

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
Jul 23 '05 #8
On 28 Sep 2004 19:54:45 -0700, rc*******@my-deja.com (Robert) wrote:
ji*@jibbering.com (Jim Ley) wrote in message news:<41**************@news.individual.net>...
http://www.webreference.com/js/tips/990928.html

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


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 mi****@mouse.com, or su*****@yourdomain.com
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.
Jul 23 '05 #9
Jim Ley wrote:
But please don't use that one, as it rejects completely valid email
addresses. 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.


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
me@hotmail.co or me@hotmail.coom 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 :)

--
Matt Kruse
http://www.JavascriptToolbox.com
Jul 23 '05 #10
On Wed, 29 Sep 2004 09:54:51 -0500, "Matt Kruse"
<ne********@mattkruse.com> wrote:
Jim Ley wrote:
But please don't use that one, as it rejects completely valid email
addresses.
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.


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 ji***********@jibbering.com - 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.
Jul 23 '05 #11
ji*@jibbering.com (Jim Ley) wrote in message news:<41****************@news.individual.net>...
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 mi****@mouse.com, or su*****@yourdomain.com
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/webmat...al.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
Jul 23 '05 #12
JRS: In article <41****************@news.individual.net>, dated Wed, 29
Sep 2004 08:59:36, seen in news:comp.lang.javascript, Jim Ley
<ji*@jibbering.com> posted :
On 28 Sep 2004 19:54:45 -0700, rc*******@my-deja.com (Robert) wrote:
ji*@jibbering.com (Jim Ley) wrote in message news:<41**************@news.indivi

dual.net>...
http://www.webreference.com/js/tips/990928.html

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


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.


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 fa********@service.invalid , so it can
be really useful to insert Fred <fa********@service.invalid> 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.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #13
Robert wrote:
[...] Jim Ley [...] wrote [...]:


Please do not post attribution novels.
http://www.webreference.com/js/tips/990928.html


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


Does someone have one to recommend?


RFC 2822, section 3.4.1, might be a good start.
PointedEars
--
The taxidermist is a lonely man.
Jul 23 '05 #14

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

Similar topics

3
by: cv | last post by:
Hello All, I have used MultipartRequest like the following to upload images. MultipartRequest multi = new MultipartRequest(request, "../webapps/coreprogram/dealerlogos", 1024 * 1024); It...
4
by: Field | last post by:
Hi, the following snippet shows once executed this output: 2 2 I'd have rather expected this output: 2 10
4
by: Reena | last post by:
Hi, code from .aspx page... using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web;
4
by: Das | last post by:
Hi, I have made an application in ASP.net with C#. The application works fine with localhost. I have uploaded the site. I'm using web user controls in the form. but some of the button do not work...
1
by: Newbie in ChiTown | last post by:
Here's my code: I am using MS Access and I am trying to update a table (InvoiceDetails) with data input by the user on a form. However, it does not update nor does it give me an error message. ...
11
by: Jim | last post by:
Hi, I want to schedule a Python program that reads the command line for input. However, when adding an argument to the command line Python will not pick it up when using Windows scheduled...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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...
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)...
0
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...
0
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.