indexOf does not work?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jenny

    indexOf does not work?

    Hi All,

    I have this code. When I type in jenny@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=valida teInput()>
    </form>
    <script type="text/javascript">
    this.myForm.use rEmail.select()
    function validateInput() {
    userInput = this.myForm.use rEmail.value
    document.write( userInput)
    if (userInput.inde xOf('@')>0 && userInput.index Of('.')>0)
    alert("Thanks for your interest.")
    else
    alert("Please check that your email details are correct before
    submitting")
    }
    </script>
  • Jeff North

    #2
    Re: indexOf does not work?

    On 25 Sep 2004 22:25:02 -0700, in comp.lang.javas cript
    jenny_jones_79@ hotmail.com (Jenny) wrote:
    [color=blue]
    >| Hi All,
    >|
    >| I have this code. When I type in jenny@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=valida teInput()>
    >| </form>
    >| <script type="text/javascript">
    >| this.myForm.use rEmail.select()
    >| function validateInput() {
    >| userInput = this.myForm.use rEmail.value
    >| document.write( userInput)[/color]

    Replace the above line with alert( userInput );
    [color=blue]
    >| if (userInput.inde xOf('@')>0 && userInput.index Of('.')>0)
    >| alert("Thanks for your interest.")
    >| else
    >| alert("Please check that your email details are correct before
    >| submitting")
    >| }
    >| </script>[/color]

    ---------------------------------------------------------------
    jnorth@yourpant sbigpond.net.au : Remove your pants to reply
    ---------------------------------------------------------------

    Comment

    • Lee

      #3
      Re: indexOf does not work?

      Jenny said:[color=blue]
      >
      >Hi All,
      >
      >I have this code. When I type in jenny@ebay.com, it should run
      >alert("Thank s 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=valid ateInput()>
      ></form>
      ><script type="text/javascript">
      >this.myForm.us erEmail.select( )
      >function validateInput() {
      >userInput = this.myForm.use rEmail.value
      >document.write (userInput)[/color]

      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.

      Comment

      • Robert

        #4
        Re: indexOf does not work?

        In article <88d928c2.04092 52125.b49f6cb@p osting.google.c om>,
        jenny_jones_79@ hotmail.com (Jenny) wrote:
        [color=blue]
        > if (userInput.inde xOf('@')>0 && userInput.index Of('.')>0)[/color]

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

        See:


        Robert

        Comment

        • Jim Ley

          #5
          Re: indexOf does not work?

          On Sun, 26 Sep 2004 17:16:19 GMT, Robert <rccharles@my-deja.com>
          wrote:
          [color=blue]
          >In article <88d928c2.04092 52125.b49f6cb@p osting.google.c om>,
          > jenny_jones_79@ hotmail.com (Jenny) wrote:
          >[color=green]
          >> if (userInput.inde xOf('@')>0 && userInput.index Of('.')>0)[/color]
          >
          >There are more complete tests to verify an email address if you are
          >interested.
          >
          >See:
          > http://www.webreference.com/js/tips/990928.html[/color]

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

          Jim.

          Comment

          • Dr John Stockton

            #6
            Re: indexOf does not work?

            JRS: In article <rccharles-6F57BE.13222426 092004@news1.we st.earthlink.n
            et>, dated Sun, 26 Sep 2004 17:16:19, seen in news:comp.lang. javascript,
            Robert <rccharles@my-deja.com> posted :[color=blue]
            >In article <88d928c2.04092 52125.b49f6cb@p osting.google.c om>,
            > jenny_jones_79@ hotmail.com (Jenny) wrote:
            >[color=green]
            >> if (userInput.inde xOf('@')>0 && userInput.index Of('.')>0)[/color]
            >
            >There are more complete tests to verify an email address if you are
            >interested.
            >
            >See:
            > http://www.webreference.com/js/tips/990928.html[/color]

            It is *not* possible to verify an e-mail address -
            <URL:http://www.merlyn.demo n.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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
            <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
            <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

            Comment

            • Grant Wagner

              #7
              Re: indexOf does not work?

              Jim Ley wrote:
              [color=blue]
              > On Sun, 26 Sep 2004 17:16:19 GMT, Robert <rccharles@my-deja.com>
              > wrote:
              >[color=green]
              > >In article <88d928c2.04092 52125.b49f6cb@p osting.google.c om>,
              > > jenny_jones_79@ hotmail.com (Jenny) wrote:
              > >[color=darkred]
              > >> if (userInput.inde xOf('@')>0 && userInput.index Of('.')>0)[/color]
              > >
              > >There are more complete tests to verify an email address if you are
              > >interested.
              > >
              > >See:
              > > http://www.webreference.com/js/tips/990928.html[/color]
              >
              > But please don't use that one, as it rejects completely valid email
              > addresses.[/color]

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

              --
              Grant Wagner <gwagner@agrico reunited.com>
              comp.lang.javas cript FAQ - http://jibbering.com/faq

              Comment

              • Robert

                #8
                Re: indexOf does not work?

                jim@jibbering.c om (Jim Ley) wrote in message news:<41573167. 8926545@news.in dividual.net>.. .
                http://www.webreference.com/js/tips/990928.html[color=blue]
                >
                > But please don't use that one, as it rejects completely valid email
                > addresses.[/color]

                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

                Comment

                • Jim Ley

                  #9
                  Re: indexOf does not work?

                  On 28 Sep 2004 19:54:45 -0700, rccharles@my-deja.com (Robert) wrote:
                  [color=blue]
                  >jim@jibbering. com (Jim Ley) wrote in message news:<41573167. 8926545@news.in dividual.net>.. .
                  > http://www.webreference.com/js/tips/990928.html[color=green]
                  >>
                  >> But please don't use that one, as it rejects completely valid email
                  >> addresses.[/color]
                  >
                  >Does someone have one to recommend?[/color]

                  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 mickey@mouse.co m, or support@yourdom ain.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.

                  Comment

                  • Matt Kruse

                    #10
                    Re: indexOf does not work?

                    Jim Ley wrote:[color=blue][color=green][color=darkred]
                    >>> But please don't use that one, as it rejects completely valid email
                    >>> addresses.[/color]
                    >> Does someone have one to recommend?[/color]
                    > 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.[/color]

                    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.
                    [color=blue]
                    > people don't type in
                    > invalid email addresses unless they're also going to type invalid but
                    > syntactically correct if forced to.[/color]

                    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



                    Comment

                    • Jim Ley

                      #11
                      Re: indexOf does not work?

                      On Wed, 29 Sep 2004 09:54:51 -0500, "Matt Kruse"
                      <newsgroups@mat tkruse.com> wrote:
                      [color=blue]
                      >Jim Ley wrote:[color=green][color=darkred]
                      >>>> But please don't use that one, as it rejects completely valid email
                      >>>> addresses.
                      >>> Does someone have one to recommend?[/color]
                      >> 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.[/color]
                      >
                      >I think this is worrying too much about a situation that will never happen.[/color]

                      Businesses have lost many thousands of pounds worth of sales because
                      they reject jim+theirname@j ibbering.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)
                      [color=blue]
                      >
                      >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.[/color]

                      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.

                      Comment

                      • Robert

                        #12
                        Re: indexOf does not work?

                        jim@jibbering.c om (Jim Ley) wrote in message news:<415a78e5. 178835031@news. individual.net> ...
                        [color=blue][color=green]
                        > >Does someone have one to recommend?[/color]
                        >
                        > 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 mickey@mouse.co m, or support@yourdom ain.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.[/color]

                        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


                        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

                        Comment

                        • Dr John Stockton

                          #13
                          Re: indexOf does not work?

                          JRS: In article <415a78e5.17883 5031@news.indiv idual.net>, dated Wed, 29
                          Sep 2004 08:59:36, seen in news:comp.lang. javascript, Jim Ley
                          <jim@jibbering. com> posted :[color=blue]
                          >On 28 Sep 2004 19:54:45 -0700, rccharles@my-deja.com (Robert) wrote:
                          >[color=green]
                          >>jim@jibbering .com (Jim Ley) wrote in message news:<41573167. 8926545@news.in divi[/color]
                          >dual.net>...[color=green]
                          >> http://www.webreference.com/js/tips/990928.html[color=darkred]
                          >>>
                          >>> But please don't use that one, as it rejects completely valid email
                          >>> addresses.[/color]
                          >>
                          >>Does someone have one to recommend?[/color]
                          >
                          >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.[/color]

                          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 familyname@serv ice.invalid , so it can
                          be really useful to insert Fred <familyname@ser vice.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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
                          <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                          <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                          Comment

                          • Thomas 'PointedEars' Lahn

                            #14
                            Re: indexOf does not work?

                            Robert wrote:
                            [color=blue]
                            > [...] Jim Ley [...] wrote [...]:[/color]

                            Please do not post attribution novels.
                            [color=blue][color=green][color=darkred]
                            >>> http://www.webreference.com/js/tips/990928.html[/color]
                            >>
                            >> But please don't use that one, as it rejects
                            >> completely valid email addresses.[/color]
                            >
                            > Does someone have one to recommend?[/color]

                            RFC 2822, section 3.4.1, might be a good start.


                            PointedEars
                            --
                            The taxidermist is a lonely man.

                            Comment

                            Working...