I am trying to add a custom validation to check for any free emailaddress from domains like [gmail, yahoo etc].

some thing similar to this [https://stackoverflow.com/questions/8271578/check-if-an-email-address-is-not-a-free-webmail-hotmail-yahoo]

I have come up with the below code, though my code checks correctly, inspite of being returning false! the form gets submitted :-|

Has anyone implemented custom validation like this using reg-ex on Smart Capture? Any inputs help links please.

My code:

var flag = 'no';


      // Get the email value from the input with an id="email"
    var email_addr = $('#email').val();

    // The regex to check it against
    var re = '[a-zA-Z0-9_\\.-]+@((hotmail)|(yahoo)|(gmail))\\.[a-z]{2,4}';

    // Check if the email matches
        alert("You cannot use free email address!");
  flag = 'yes';
        // Email is on the filter list
        // Return false and don't submit the form, or do whatever
        return false;
    } else {
     alert("Submitted Successfully!");
        // Email ok
        // Allow the form to be submitted
        return true;
}); //form

function isFreeEmail()
 if(flag == 'yes')
 return false;
 return true;

On smart capture form, added ONSUBMIT as below

<form onsubmit="return isFreeEmail()" id="smartcapture-block-xxxx" class="smartcapture-content-wrapper fuelux" novalidate="novalidate">
  • Where did you test your regex? Are you sure it works? I tried three different testers now with "test@gmail.com" and it never matched. Also, are you sure about your design? How do you find "all freemailers" and put them into a list? In general though, this should absolutely work. I have done something similar using ampscript (and no smartcapture), just make sure you validate on front AND backend. Nov 24 '20 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.