Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.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
尝试使用jQuery在Gridview中检查验证电子邮件地址_Jquery_Asp.net_Gridview - Fatal编程技术网

尝试使用jQuery在Gridview中检查验证电子邮件地址

尝试使用jQuery在Gridview中检查验证电子邮件地址,jquery,asp.net,gridview,Jquery,Asp.net,Gridview,我没有从这里显示的列表中看到任何符合我们要求的示例 我们正在尝试验证几个GridView表单控件 其中之一是电子邮件控制 这些要求是: 首先,确保已输入电子邮件。这很有效。 第二个要求更具挑战性。第二部分是确保用户输入有效的电子邮件地址 我尝试过几种可能性,但迄今为止都没有成功 您知道如何使用jQuery在GridView中检查有效的电子邮件地址吗 <script type="text/javascript"> $(function () { $("[id*=

我没有从这里显示的列表中看到任何符合我们要求的示例

我们正在尝试验证几个GridView表单控件

其中之一是电子邮件控制

这些要求是:

首先,确保已输入电子邮件。这很有效。 第二个要求更具挑战性。第二部分是确保用户输入有效的电子邮件地址

我尝试过几种可能性,但迄今为止都没有成功

您知道如何使用jQuery在GridView中检查有效的电子邮件地址吗

<script type="text/javascript">
    $(function () {
        $("[id*=GridView1] [id*=btnAdd]").click(function () {
            //Find the GridView Row using the LinkButton reference.
            var row = $(this).closest("tr");
            //Find the request type TextBox control.
            var txtrequestType = row.find("[id*=txtrequestType]");
            var txtemailAdd = row.find("[id*=txtemailAdd]");

            //Find the DropDownList control.
            //  var ddlCountries = row.find("[id*=ddlCountries]");
            var message = "";
            //Validate the request type TextBox control.
            if ($.trim(txtrequestType.val()) == "") {
                message += "Please enter a new request type.\n";
            }
            //Validate the email TextBox control.
            if ($.trim(txtemailAdd.val()) == "") {
                message += "Please enter a new email address.\n";
            }
           // This validation is not working
            if (!(txtemailAdd.indexOf('@') == -1)) {
                message += "Please enter a valid email address.\n";
            }
            //Validate the DropDownList control.
            //   if (ddlCountries.val() == "") {
            //     message += "Please select Country.";
            // }
            //Display error message.
            if (message != "") {
                alert(message);
                return false;
            }
            return true;
        });
    });
</script>

$(函数(){
$(“[id*=GridView1][id*=btnAdd]”。单击(函数(){
//使用LinkButton引用查找GridView行。
var行=$(此).tr;
//查找请求类型TextBox控件。
var txtrequestType=row.find(“[id*=txtrequestType]”);
var txtemailAdd=row.find(“[id*=txtemailAdd]”);
//查找DropDownList控件。
//var ddlCountries=row.find(“[id*=ddlCountries]”);
var message=“”;
//验证请求类型TextBox控件。
if($.trim(txtrequestType.val())==“”){
消息+=“请输入新的请求类型。\n”;
}
//验证电子邮件文本框控件。
if($.trim(txtemailAdd.val())==“”){
message+=“请输入新的电子邮件地址。\n”;
}
//此验证不起作用
if(!(txtemailAdd.indexOf('@')=-1)){
message+=“请输入有效的电子邮件地址。\n”;
}
//验证DropDownList控件。
//如果(ddlCountries.val()==“”){
//消息+=“请选择国家。”;
// }
//显示错误消息。
如果(消息!=“”){
警报(信息);
返回false;
}
返回true;
});
});

如果
@
存在,您的条件逻辑是向后的并返回true。。。摆脱
@charlietfl,非常感谢。这是我在这里发布之前尝试的一个新解决方案,但忘记了进行更正。它现在正在运行,下面是运行的脚本。
if (($.trim(txtemailAdd.val()).indexOf('@') == -1)) {
    message += "Please enter a valid email address.\n";
}