Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > indexOf does not work?

Reply
Thread Tools

indexOf does not work?

 
 
Jenny
Guest
Posts: n/a
 
      09-26-2004
Hi All,

I have this code. When I type in http://www.velocityreviews.com/forums/(E-Mail 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>
 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      09-26-2004
Jenny said:
>
>Hi All,
>
>I have this code. When I type in (E-Mail 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.

 
Reply With Quote
 
 
 
 
Jeff North
Guest
Posts: n/a
 
      09-26-2004
On 25 Sep 2004 22:25:02 -0700, in comp.lang.javascript
(E-Mail Removed) (Jenny) wrote:

>| Hi All,
>|
>| I have this code. When I type in (E-Mail 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 );

>| 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>


---------------------------------------------------------------
(E-Mail Removed) : Remove your pants to reply
---------------------------------------------------------------
 
Reply With Quote
 
Jim Ley
Guest
Posts: n/a
 
      09-26-2004
On Sun, 26 Sep 2004 17:16:19 GMT, Robert <(E-Mail Removed)>
wrote:

>In article <(E-Mail Removed)> ,
> (E-Mail Removed) (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.
 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      09-27-2004
JRS: In article <(E-Mail Removed)
et>, dated Sun, 26 Sep 2004 17:16:19, seen in news:comp.lang.javascript,
Robert <(E-Mail Removed)> posted :
>In article <(E-Mail Removed)> ,
> (E-Mail Removed) (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.
 
Reply With Quote
 
Grant Wagner
Guest
Posts: n/a
 
      09-27-2004
Jim Ley wrote:

> On Sun, 26 Sep 2004 17:16:19 GMT, Robert <(E-Mail Removed)>
> wrote:
>
> >In article <(E-Mail Removed)> ,
> > (E-Mail Removed) (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 <(E-Mail Removed)>
comp.lang.javascript FAQ - http://jibbering.com/faq

 
Reply With Quote
 
Robert
Guest
Posts: n/a
 
      09-29-2004
(E-Mail Removed) (Jim Ley) wrote in message news:<(E-Mail Removed)>...
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
 
Reply With Quote
 
Jim Ley
Guest
Posts: n/a
 
      09-29-2004
On 28 Sep 2004 19:54:45 -0700, (E-Mail Removed) (Robert) wrote:

>(E-Mail Removed) (Jim Ley) wrote in message news:<(E-Mail Removed)>...
> 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 (E-Mail Removed), or (E-Mail 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.
 
Reply With Quote
 
Matt Kruse
Guest
Posts: n/a
 
      09-29-2004
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
(E-Mail Removed) or (E-Mail 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

--
Matt Kruse
http://www.JavascriptToolbox.com


 
Reply With Quote
 
Jim Ley
Guest
Posts: n/a
 
      09-29-2004
On Wed, 29 Sep 2004 09:54:51 -0500, "Matt Kruse"
<(E-Mail Removed)> 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 (E-Mail 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
string.indexof case insensitive Guoqi Zheng ASP .Net 4 01-25-2009 02:07 AM
IndexOf and LastIndexOf not working .Net Sports ASP .Net 2 01-18-2006 04:40 PM
indexOf is not a function Shang Wenbin Javascript 2 08-11-2005 04:01 PM
Object not set to an instance (ERROR) INDEXOF in do loop? jason@cyberpine.com ASP .Net 2 06-06-2004 07:35 AM
HowTo use CompareMethod.Text in String.IndexOf ? Andreas Klemt ASP .Net 0 03-06-2004 03:37 AM



Advertisments