Skip to content

Instantly share code, notes, and snippets.

@johnnyopao
Last active March 31, 2024 10:03
Show Gist options
  • Save johnnyopao/c9965db11cded79aede6 to your computer and use it in GitHub Desktop.
Save johnnyopao/c9965db11cded79aede6 to your computer and use it in GitHub Desktop.
Confirm Email Validation
<script>
lp.jQuery(function($) {
var ruleID = 'emailMatch';
//The email field to check against
var firstEmailField = 'email';
//The second confirmation email field
var secondEmailfield = 'confirm_email';
var message = 'Email addresses do not match';
var rules = module.lp.form.data.validationRules[secondEmailfield];
$.validator.addMethod(ruleID, function(value, secondEmailfield) {
var emailValue = $('#' + firstEmailField ).val();
var valid = ( value === emailValue );
return valid || (!rules.required && !value);
}, message);
rules[ruleID] = true;
});
</script>
@yehanny-ldm
Copy link

Well this is an old post but I think is still relevant for others like me, there’s an elegant way to do this with the latest UnBounce Version, and you can also validate other fields using this algorithm. Happy coding to you all.

`<script>
/* Confirm email */
window.ub.form.customValidators.nonValidEmailConfirm = {
isValid: function(value) {
let email_confirm = value.toLowerCase();
let email = document.getElementById('email');
return value.match(email.value);
},
message: 'Email does not match',
};

window.ub.form.validationRules.email_confirm.nonValidEmailConfirm = true;

</script> `

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment