存在重复电子邮件时发出警报消息

Alert message when there is duplicate email

本文关键字:消息 电子邮件 存在      更新时间:2023-09-26

当存在重复的电子邮件地址时,我需要显示一条警告消息。

这是我的代码:

$.validator.addMethod("contactpersonen-email", function(value, element) {
    var parentForm = $(element).closest('form');
    var timeRepeated = 0;
    if (value != '') {
        $(parentForm.find(':text')).each(function () {
            if ($(this).val() === value) {
                timeRepeated++;
            }
        });
    }
    return timeRepeated === 1 || timeRepeated === 0;
    alert('duplicate');
}, "Email adres bestaat al");

但它不起作用。你能找出问题并解决它吗?

$.validator.addMethod("contactpersonen-email", function(value, element) {
    var parentForm = $(element).closest('form');
    var timeRepeated = 0;
    if (value != '') {
        $(parentForm.find(':text')).each(function () {
            if ($(this).val() === value) {
                timeRepeated++;
            }
        });
    }
    var ok = timeRepeated === 1 || timeRepeated === 0;
    if(!ok) alert('duplicate');
    return ok;
}, "Email adres bestaat al");