Last active
March 31, 2024 10:03
-
-
Save johnnyopao/c9965db11cded79aede6 to your computer and use it in GitHub Desktop.
Confirm Email Validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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> `