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 5 of 5
  1. #1
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    Hi,

    I'm trying to figure out the best solution for my e-mail submission box at my website here. Because of the predefined string methods in JS, namely match() and substring(), I want to do the following:

    Test if the submission has a '@' and a '.com', '.net', '.org', '.biz', etc. in it.

    Is there an equivalent method to PHP's $_GET or $_POST for JavaScript to grab the data just submitted from the input field in the form with the name 'go'?

    Thanks for the help.

  2.  

  3. #2
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    You can do this with the querystring (GET params), but not with post data, as that's part of the http request, which javascript doesn't have access to.

    Here you go: http://stackoverflow.com/questions/9...-string-values

  4. #3
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    Thanks, but I still have a question about what are all of these slashes in the code?
    Code:
    {
      name = name.replace(/\/, "\\\[").replace(/[\]]/, \\\]);
      var regexS = "[\\?&]" + name + "=([^&#]*)";
      var regex = new RegExp(regexS);
      var results = regex.exec(window.location.search);
      if(results == null)
        return "";
      else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
    }

  5. #4
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Some are escapes, and others are regex delimiters.

  6. #5
    Member
    Join Date
    Nov 2012
    Location
    Tampa. FL
    Posts
    59
    Member #
    33844
    Liked
    21 times
    You can get the value with $('#go').val();
    What you should do is create a function for the submit method of the form and use jquery to test the email address and return false (if it's not a valid address) to prevent the form from submitting. Something like:
    $('#emailbox').submit(function(){
    var email = $('#go').val();
    if(validate(email){
    return true;
    }else{
    return false
    }
    });
    Then you will need a function called validate that takes the parameter of email and tests whether it's valid with your regex.
    Freelance Web Developer


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 01:26 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com