Jquery验证手机号码已存在

时间:2017-03-07 07:23:23

标签: c# jquery asp.net

用于在提交时验证表单的Jquery代码:

 $("#frmAddEditCustomer").validate({
            rules: {
                //"companyname": "required",
                "txtcustomerid": "required",
                "mobile1": {
                    required: true,
                    digits: true,
                    minlength: 8,
                    remote: {
                        url: "AdminWeb.asmx/HelloWorld",
                        type: "post",
                        data: {
                            mobile1: function () { return $("#mobile1").val(); }
                        }
                    }
                },
                "remark": "required",
                "firstname": "required",
                "email": {
                    required: true,
                    email: true,
                },
                "lastname": "required",

            },
            messages: {
                "txtcustomerid": "CustomerID is required",
                //"companyname": "Company Name is required",
                "mobile1": {
                    required: "Mobile Number is required",
                    digits: "Please enter only digits.",
                    minlength: "Please enter at least 8 digits.",
                    remote: "Mobile number already in use!"
                },
                "email": {
                    required: "Email Address is required",
                    email: "Enter proper Email Address"
                },
                "remark": "Short Note is required",
                "firstname": "First Name is required",
                "lastname": "Last Name is required",
            },
            submitHandler: function (form) {
                if ($("#hidEditID").val() > 0) {
                    EditCustomer();
                }
                else {
                    AddCustomer();
                }
                return false;
            }
        });

网址调用方法:

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public bool HelloWorld()
{
    return false;
}

我想验证mobile1号码,如果已经存在于数据库中那么它应该显示远程默认的错误消息我传递给false以获取错误但它不起作用。 请帮我解决这个问题。

0 个答案:

没有答案