JQuery Validation Plugin addmethod
I have make addmethod for Validation Plugin but is always showing true. I don't what is the problem. I cheked in Firebug it is returning correct result and also sending correct text. But still companyNameCheck method behaving wired. Following is my JQuery Code
- $("#frmCompany").validate({
rules:
{
fvCompany$txCompanyName:
{
required: true,
companyNameCheck: true
},
fvCompany$txTelephone1:
{
number: true,
minlength: 8
},
fvCompany$txTelephone2:
{
number: true,
minlength: 8
},
fvCompany$txFax:
{
number: true,
minlength: 8
},
fvCompany$txEmailID:
{
email: true
}
},
messages:
{
fvCompany$txCompany_Name:
{
required: "Provide Company Name",
companyNameCheck: "Company already exits"
},
fvCompany$txTelephone1:
{
number: "Only digits are allowed",
minlength: jQuery.format("Enter at least {0} digits.")
},
fvCompany$txTelephone2:
{
number: "Only digits are allowed",
minlength: jQuery.format("Enter at least {0} digits.")
},
fvCompany$txFax:
{
number: "Only digits are allowed",
minlength: jQuery.format("Enter at least {0} digits.")
}
},
success: function (label) {
// set as text for IE
label.html(" ").addClass("positive");
},
errorPlacement: function (error, element) {
error.appendTo(element.parent().next());
}
});
});
jQuery.validator.addMethod('SelectNone', function (value, element) {
return this.optional(element) || (value.indexOf("-- Please Select --") == -1);
}, '');
jQuery.validator.addMethod('companyNameCheck', function (companyName) {
var postURL = "WebService.asmx/GetExactCompany";
$.ajax({
cache: false,
async: false,
type: "POST",
url: postURL,
data: "{'companyName':'" + String(companyName) + "'}", //data
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
result = (msg == "1" ? true : false);
}
});
return result;
}, '');
This is my Webservice Webmethod
- <WebMethod()> _
Public Function GetExactCompany(ByVal companyName As String) As String
Dim available As String = ""
Dim companyAPI As New CompanyBLL
Dim company As HelpDesk.CompanyDataTable = companyAPI.GetCompanyByExactCompanyName(companyName)
Try
If company.Rows.Count > 0 Then
available = "0"
Else
available = "1"
End If
Catch ex As Exception
'Setup a breakpoint here
'to verify any exceptions raised.
Dim exp As String = ex.ToString()
End Try
Return available
End Function
Above is used in asp.net 4.0 in FormView InsertTemplate. Can somebdoy tell me what wrong I might be doing