我们将其用于调用 ASP.Net Web 服务的 ajax 验证规则。您所要做的就是在您的语言文件中编写规则。
这是我们的:
"ajaxEmailCheck": {
"url": "/json_api/AjaxEmailCheck/",
"extraDataDynamic": ['#EmailAddress'],
"alertText": "* An Account with this email has already been created.",
"alertTextLoad": "* Validating, please wait..."
},
这个调用 url /json_api/AjaxEmailCheck 并传递电子邮件地址。然后我们的字段定义如下:
<input type="email"
name="email_address"
title="Email Address"
id="email_address"
class="validate[required,custom[onlyLetNumSpec],ajax[ajaxEmailCheck]]
/>
此外,这是上面使用的 onlyLetNumSpc 规则:
"onlyLetNumSpec": {
// Good for database fields
"regex": /^[^\\]+$/,
"alertText": "* Any Character is allowed with the exception of backslash(\)."
}
从 Web 服务返回的数据如下所示:
"{"EmailAddress":true}"
如果传递的电子邮件已经存在:
"{"EmailAddress":false,"Error":"* An Account with this email has already been created."}"