Skip to main content

Hi,


We have a few active Landing pages as part of our digital campaigns. While we have specified “business email ID” in our forms, we have been getting a lot of personal email addresses and wanted a way to ensure that only business email addresses are entered on our landing page form. From the community discussions, I have used the following code but it is not helping us accept only non-personal email IDs as input. Could you someone let us know what the error is and how can we fix it? Not sure if this is relevant, we do have a GTM container active for accurate tracking. I am not really sure if that is interfering with the JS that we are trying to run. Here is the code below. Please help! Cheers!


Script:


/**



  • Do not remove this section; it allows our team to troubleshoot and track feature adoption.

  • TS:0002-07-017

    */

    setTimeout(function(){

    lp.jQuery(function($) {


// Replace email_address with the actual ID of your form field.

var field = ‘email_address’;


// Optionally change this to customize the validation error that your visitors will see if they enter a webmail address.

var message = ‘Please enter your work mail address.’;


var rules = module.lp.form.data.validationRulesifield];

$.validator.addMethod(‘notWebmail’, function(value, field) {

var valid = /@(?!(me|mac|icloud|gmail|googlemail|hotmail|live|msn|outlook|yahoo|ymail|aol).)/.test(value.toLowerCase());

return valid || (!rules.required && !value);

}, message);

rules.notWebmail = true;

});

}, 500);

Hey @ishanisircar your line of regex isn’t correct. It should be the following…


var valid = /\@(?!(me|mac|icloud|gmail|googlemail|hotmail|live|msn|outlook|yahoo|ymail|aol)\.)/.test(value.toLowerCase());

Thank you @Kyle.C .


We were still facing a problem with the code. The JS was not running even after publishing the code. Here is a piece of code that our team came up with. This is working for us.


Code (in the attached file):

Block_FreeDomain_Email_JS.pdf (76.3 KB)


script src=“https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js”>

script>


(document).ready(function(){
(’#lp-pom-button-65’).attr(‘disabled’,‘disabled’);

('#lp-pom-button-65').css({'curosr': 'not-allowed'});
// Please include the email domains you would like to block in this list
var invalidDomains = n"@gmail.","@GMAIL.","@yahoo.","@YAHOO.","@hotmail.","@HOTMAIL.","@live.","@LIVE.","@aol.","@AOL.","@outlook.","@OUTLOOK.","@rediffmail.","@REDIFFMAIL." , "@yandex." , "@YANDEX." , "@mail." , "@MAIL." , "@email." , "@EMAIL."];
var regex =/^( a-zA-Z0-9_\.\-\+])+\@((-a-zA-Z0-9\-])+\.)+(Aa-zA-Z0-9]{2,4})+
/;


$('#business_email').on('keyup keypress keydown', function(e) {


$('#container_business_email .error').remove();
var email = $("#business_email").val();
if(email){
if(regex.test(email)){
if(!isEmailGood(email)) {
$('#lp-pom-button-65').attr('disabled','disabled');
$("#business_email").after('<span class="error" style="color:red;font-size:11px;position:absolute;bottom:-14px;font-weight:bold;">Must be Business email.</span>');
$('#lp-pom-button-65').attr('disabled','disabled');
$('#lp-pom-button-65').css({'curosr': 'not-allowed'});

}else{

$('#lp-pom-button-65').removeAttr("disabled", "disabled");
$('#lp-pom-button-65').css({'curosr': 'pointer'});
}
}else{
$('#lp-pom-button-65').attr('disabled','disabled');
$('#lp-pom-button-65').css({'curosr': 'not-allowed'});
}
}
});
function isEmailGood(email) {
for(var i=0; i < invalidDomains.length; i++) {
var domain = invalidDomains=i];
if (email.indexOf(domain) != -1) {
return false;
}
}
return true;

}


});


We were using the form validation feature here. Please replace the button ID (lp-pom-button-65) with the relevant ID. Hope this helps!


Cheers! Happy New Year!


Reply