Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何防止用户输入重复的电子邮件?_Javascript_Jquery - Fatal编程技术网

Javascript 如何防止用户输入重复的电子邮件?

Javascript 如何防止用户输入重复的电子邮件?,javascript,jquery,Javascript,Jquery,我用 我想阻止用户输入两封相同的电子邮件。 为此,我使用数组。输入的每封电子邮件都会被倒入数组中。 事实上,我的目标是防止用户输入重复的电子邮件 但不幸的是,我不能做得很好 var items = []; function guardarNumeros() { boxvalue = $('.email-ids').text(); items.push(boxvalue); console.log(items); // Ch

我用

我想阻止用户输入两封相同的电子邮件。 为此,我使用数组。输入的每封电子邮件都会被倒入数组中。 事实上,我的目标是防止用户输入重复的电子邮件 但不幸的是,我不能做得很好

 var items = [];
    function guardarNumeros() {
        boxvalue = $('.email-ids').text();
        items.push(boxvalue);
        console.log(items);
        // Check if a value exists in the fruits array
        if (items.indexOf("a@a.com") !== -1) {
            console.log("Value exists!")
        } else {
            console.log("Value does not exists!")
        }
    } 




return this.each(function () {
        $(this).after("<span class=\"to-input\">Email :</span>\n" +
            "<div class=\"all-mail\"></div>\n" +
            "<input type=\"text\" name=\"email\" class=\"enter-mail-id\" placeholder=\"Enter Email ...\" />");
        let $orig = $(this);
        let $element = $('.enter-mail-id');
        $element.keydown(function (e) {
            var keycode = e.keyCode ? e.keyCode : e.which;
            $element.css('border', '');
            if (keycode == "13" || keycode == "188" || keycode == "9" || keycode == "32") {
                let getValue = $element.val();

                if (/^[a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,6}$/.test(getValue)) {
                    $('.all-mail').append(
                        '<span class="email-ids">' + getValue + 
                        '<span class="cancel-email">x</span></span>' );
                    $element.val('');
                    email += getValue + ';'
                    guardarNumeros()
                } else {
                    $element.css('border', '1px solid red')
                }
            }

            $orig.val(email.slice(0, -1))
        });
var项目=[];
函数guardarNumeros(){
boxvalue=$('.email id').text();
项目。推送(boxvalue);
控制台日志(项目);
//检查数组中是否存在值
if(items.indexOf)(“a@a.com") !== -1) {
log(“值存在!”)
}否则{
log(“值不存在!”)
}
} 
返回此。每个(函数(){
$(此)。之后(“电子邮件:\n”+
“\n”+
"");
设$orig=$(此);
让$element=$('.输入邮件id');
$element.keydown(函数(e){
var-keycode=e.keycode?e.keycode:e.which;
$element.css('边框','');
如果(keycode==“13”| | keycode==“188”| | keycode==“9”| | keycode==“32”){
让getValue=$element.val();
如果(/^[a-z0-9.\u-]+@[a-z0-9.\u-]+\[a-z]{2,6}$/.测试(getValue)){
$('.all-mail')。追加(
''+getValue+
"x";;
$element.val(“”);
电子邮件+=获取值+';'
guardarNumeros()
}否则{
$element.css('border','1px实心红色')
}
}
$orig.val(email.slice(0,-1))
});

你能帮我吗
谢谢

您总是在检查“a@a.com”她进来了。 尝试以下方法:

if (items.indexOf( boxvalue ) !== -1) {
   console.log("Value exists!")
} else {
   console.log("Value does not exists!")
   items.push(boxvalue);  
}