Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Streety 358 posts 568 karma points
    Apr 16, 2012 @ 10:36
    Streety
    0

    Regex validation on Email address...

    Hi Guys.

    I have found the section in your simple.js file to check for null values in the checkout page

     

      if (formObj.email === '') {
        pageValidateText += '\nE-mail';
      }

     

    How could I mod this to check for a valid email. I'd want to use a regex expression like this to validate:

     

    \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

     

    Thanks.

  • Anders Burla 2560 posts 8256 karma points
    Apr 16, 2012 @ 10:39
    Anders Burla
    0

    Hi Streety

    This might help you: http://www.regular-expressions.info/javascript.html

    Kind regards
    Anders

  • Streety 358 posts 568 karma points
    Apr 16, 2012 @ 12:24
    Streety
    0

    Thanks for that Anders.

    Please forgive my JS. Something like this? 

       

    var valid_email = new RegExp("\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");

    if (formObj.email.match(valid_email)) {

    alert(

    "Successful match");

    }

    else {

    alert(

    "No match");

    }

     Doesn't work though.

  • Grant Thomas 291 posts 324 karma points
    Apr 16, 2012 @ 12:44
    Grant Thomas
    0

    Just ina case you didn't know: that regex won't strictly 'validate' email addresses. You might wish to read this, or Google for some info on the near inability to actually do so.

  • Streety 358 posts 568 karma points
    Apr 16, 2012 @ 12:58
    Streety
    0

    Hmmm. Wondered why such a basic function is missing from the sample website.

    The validation of email and postcodes is rather bread & butter wouldn't you say?

  • Streety 358 posts 568 karma points
    Apr 16, 2012 @ 16:04
    Streety
    0

    I am a little further forward with this:

    I have a functional called Validate that can check the input string on the email input.

     function validate() {
        var paymentInformation = jQuery("#paymentInformation");
        var email = paymentInformation.find("#email").val();
        if (validateEmail(email)) {
        //        $("#result").text("good email");
        //        $("#result").css("color", "Green");
        } else {
        //        $("#result").text("bad email");
        //        $("#result").css("color", "red");
          
        }
        return false;
    }

    function validateEmail(email) {
        var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return re.test(email);
    }

    However I havn't figured how o tie it into the existing PageValidateText routine and work.

    Any support would be greatly received.

  • Anders Burla 2560 posts 8256 karma points
    Apr 16, 2012 @ 16:30
    Anders Burla
    0

    Doesn't the if(validateEmail('[email protected]')) works? That should return true. Else try and make an alert in the validateEmail method and see what re.test(email) returns.

    Kind regards
    Anders

  • Streety 358 posts 568 karma points
    Apr 16, 2012 @ 17:18
    Streety
    0

    Yes the method works however I can't seem to wire in to your pagevalidattext statement.

    This checks to see if any validation message have been posted and it not,  allows the process to continue.

    if

     

     

    (pageValidateText != '') {

     I want to able to use the existing frame to add a new validation message "bad email" to the pagevalidationtext

    var pageValidateText = '';

     

  • Streety 358 posts 568 karma points
    Apr 16, 2012 @ 17:19
    Streety
    1

    This html editor on this forum is so pants.

  • Anders Burla 2560 posts 8256 karma points
    Apr 17, 2012 @ 01:40
    Anders Burla
    0

    Cant you just make something like this in the teaCommerce_Simple.js

    if (!validateEmail()) {
        pageValidateText += '\nBad email!!';
      }

    Kind regards
    Anders

Please Sign in or register to post replies

Write your reply to:

Draft