本文介绍了检查文本框值是2个有效的电子邮件ID,使用逗号分隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究MVC 5,我希望在文本框中插入两个电子邮件ID,并使用逗号分隔,并且只允许显示2或1个电子邮件,如下图所示。



[]



什么我试过了:



我在提交按钮点击时尝试了jquery代码,



I am working on MVC 5, there I want to insert two Email Id inside textbox with comma seperated and also should allow only 2 or 1 emailids like below image shown.

[^]

What I have tried:

I have tried jquery code on submit button click,

submitPrimUserAllReg = {  
    submitUser: function () {  
        debugger;  
        if (!$('#hdTurnOver').val() == '' && !$('#hdTurnOver').val() == '') {  
            var emailid = $('#userEmailid').val().split(",");  
            var validemail = [];  
            $.each(emailid, function (i) {  
  
                if (!isEmail(emailid[i])) {  
                    alert('Please Enter Valid EmailID');  
                    return false;  
                }  
                else {  
                    validemail.push(emailid[i]);  
                    var validemailcomma = validemail.join(",");  
                    if (!validemailcomma == '') {  
  
                        var validemailsplited = validemailcomma.split(",").length;  
                        if (validemailsplited == 2 || validemailsplited == 1) {  
                            $('#frmSubmitPremUserReg').submit();  
                            //alert('success!')  
                        }  
                        else {  
                            alert('Only two EmailID');  
                            return false;  
                        }  
                    }  
                }  
            });  
        }  
        else {  
            return false;  
        }  
    }  
}  





使用此代码后出现问题:如果emailId输入如test1 @ gmail.com,test然后表单正在提交。但在这里,我想显示请输入有效的EmailID等警告信息。我怎么解决这个问题?



请帮帮我...



After using this code, there is an issue: If the emailId enter like "[email protected],test " then the form is submitting. But here I want to show alert message like 'Please Enter Valid EmailID'. How can I solve this?

Please help me...

推荐答案




这篇关于检查文本框值是2个有效的电子邮件ID,使用逗号分隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 00:34