indexOf does not work?

Discussion in 'Javascript' started by Jenny, Sep 26, 2004.

  1. Jenny

    Jenny Guest

    Hi All,

    I have this code. When I type in , 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>
     
    Jenny, Sep 26, 2004
    #1
    1. Advertising

  2. Jenny

    Lee Guest

    Jenny said:
    >
    >Hi All,
    >
    >I have this code. When I type in , 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.
     
    Lee, Sep 26, 2004
    #2
    1. Advertising

  3. Jenny

    Jeff North Guest

    On 25 Sep 2004 22:25:02 -0700, in comp.lang.javascript
    (Jenny) wrote:

    >| Hi All,
    >|
    >| I have this code. When I type in , 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>


    ---------------------------------------------------------------
    : Remove your pants to reply
    ---------------------------------------------------------------
     
    Jeff North, Sep 26, 2004
    #3
  4. Jenny

    Jim Ley Guest

    On Sun, 26 Sep 2004 17:16:19 GMT, Robert <>
    wrote:

    >In article <>,
    > (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.
     
    Jim Ley, Sep 26, 2004
    #4
  5. JRS: In article <
    et>, dated Sun, 26 Sep 2004 17:16:19, seen in news:comp.lang.javascript,
    Robert <> posted :
    >In article <>,
    > (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.
     
    Dr John Stockton, Sep 27, 2004
    #5
  6. Jenny

    Grant Wagner Guest

    Jim Ley wrote:

    > On Sun, 26 Sep 2004 17:16:19 GMT, Robert <>
    > wrote:
    >
    > >In article <>,
    > > (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 <>
    comp.lang.javascript FAQ - http://jibbering.com/faq
     
    Grant Wagner, Sep 27, 2004
    #6
  7. Jenny

    Robert Guest

    (Jim Ley) wrote in message news:<>...
    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
     
    Robert, Sep 29, 2004
    #7
  8. Jenny

    Jim Ley Guest

    On 28 Sep 2004 19:54:45 -0700, (Robert) wrote:

    > (Jim Ley) wrote in message news:<>...
    > 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 , or
    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.
     
    Jim Ley, Sep 29, 2004
    #8
  9. Jenny

    Matt Kruse Guest

    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
    or 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
     
    Matt Kruse, Sep 29, 2004
    #9
  10. Jenny

    Jim Ley Guest

    On Wed, 29 Sep 2004 09:54:51 -0500, "Matt Kruse"
    <> 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 - 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.
     
    Jim Ley, Sep 29, 2004
    #10
  11. Jenny

    Robert Guest

    (Jim Ley) wrote in message news:<>...

    > >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 , or
    > 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
     
    Robert, Sep 29, 2004
    #11
  12. JRS: In article <>, dated Wed, 29
    Sep 2004 08:59:36, seen in news:comp.lang.javascript, Jim Ley
    <> posted :
    >On 28 Sep 2004 19:54:45 -0700, (Robert) wrote:
    >
    >> (Jim Ley) wrote in message news:<

    >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 d , so it can
    be really useful to insert Fred <> 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.
     
    Dr John Stockton, Sep 29, 2004
    #12
  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.
     
    Thomas 'PointedEars' Lahn, Oct 10, 2004
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Klemt
    Replies:
    0
    Views:
    1,171
    Andreas Klemt
    Mar 6, 2004
  2. Replies:
    2
    Views:
    418
    Peter Rilling
    Jun 6, 2004
  3. Guoqi Zheng

    string.indexof case insensitive

    Guoqi Zheng, Jul 9, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    12,959
    bentangle
    Jan 25, 2009
  4. .Net Sports

    IndexOf and LastIndexOf not working

    .Net Sports, Jan 18, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    3,819
    .Net Sports
    Jan 18, 2006
  5. Shang Wenbin

    indexOf is not a function

    Shang Wenbin, Aug 11, 2005, in forum: Javascript
    Replies:
    2
    Views:
    80
    Mick White
    Aug 11, 2005
Loading...

Share This Page