Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    I am having a bit of difficulty with an e-mail valildation question.
    I usually use regular expressions to validate e-mail, but for this particular question I need to use "indexOf" and I am having a tough time figuring out how to use it in the code I've got so far.
    HTML Code:
    <html>
    <head>
    <title>Newsletter sign-up</title>
    
    <script>
    
    function validateForm()
    {
      /* Extract the value of the firstName field from the form
          and place it in the variable fName! */
      var fName = document.getElementById("firstName").value;
    
      if ( fName == "" )
      {
          alert("Please do not leave the First Name blank!");
          document.getElementById("firstName").focus();
          return false;
      }
    
      /* Extract the value of the lastName field from the form
          and place it in the variable lName! */
      var lName = document.getElementById("lastName").value;
    
      if ( lName == "" )
      {
          alert("Please do not leave the Last Name blank!");
          document.getElementById("lastName").focus();
          return false;
      }
    
      /* Extract the value of the emailAddress field from the form
          and place it in the variable eMail! */
      var eMail = document.getElementById("emailAddress").value;
    
      if ( eMail == "" )
      {
          alert("Please do not leave the E-mail Address blank!");
          document.getElementById("emailAddress").focus();
          return false;
      }
    
      /* Extract the value of the checkbox from the form
          and place it in the variable cBox! */
      var cBox = document.getElementById("newsletter").checked;
    
      if ( cBox == false )
      {
          alert("Please click inside the checkbox to choose it!")
          document.getElementById(newsletter).focus();
          return false;
      }
      return true;
    }
    
    </script>
    </head>
    
    <body>
        <form action="#"  onSubmit="return validateForm()";>
        First Name: <input type="text" id="firstName" /></br>
        Last Name: <input type="text" id="lastName" /></br>
        Email Address: <input type="text" id="emailAddress" /></br>
        Do you want to receive our newsletter?
        <input type="checkbox" id="newsletter" /><br>
        <input type="submit" value="Sign-Up" id="signUp" />
        </form>
    
    </body>
    </html>
    It's all working so far, just have to validate the e-mail with this darned "indexOf" thing that I haven't used before.

    It's not live anywhere but could be if necessary.

    I've looked at tutorials and examples and I'm totally confused, I think I'm mixing PHP with my javascript...

    It's been a long time since I was this stymied, and it seems like it should be a simple enough thing - I'm so frustrated!

    Any help?
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!

  2.  

  3. #2
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    Anyone?
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!

  4. #3
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    Is there a particular reason why you don't want to use Regex to validate ? From reading up ( glanced at it ), no real benefit they knew of to use that ?

    Just wondering if you can enlighten me ? Or stir enough brain cells to spend more than a few minutes working it out.

  5. #4
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    Quote Originally Posted by Webzarus, post: 229896
    Is there a particular reason why you don't want to use Regex to validate ? From reading up ( glanced at it ), no real benefit they knew of to use that ?

    Just wondering if you can enlighten me ? Or stir enough brain cells to spend more than a few minutes working it out.
    Yeah, it's funny, actually.

    I'm taking a class at a local college - it's intermediate javascript. I did the beginner pre-requisite last term, but unfortunately it's not the same teacher. The new guy is starting us out slowly, and this is one of the exercises he set for the class.

    I did it using regular expressions and sent him the file. He sent back that I had jumped the gun, none of the rest of the class knew about regular expressions, and he specifically wanted us to learn about the predefined functions. That's OK, but I've never really used them except for alerts, so I'm having trouble with figuring our how to use them.

    I guess I'm one for making things more difficult than they need to be, but I've always written my own functions in PHP and didn't see any reason not to keep doing it in javascript. But I have to say that I do like the idea of having a good part of the work done for me ... I just have to make the adjustment. (I still sometimes reach for the shifter in my car, even though I've driven an automatic for a dozen years now...)
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:48 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com