Используя customValidator:
<asp:CustomValidator ID="cvEMail" runat="server" ControlToValidate="tEMail"
Display="None" ClientValidationFunction="validateEMail"
OnServerValidate="cvEMail_ServerValidate"/>
<span id="lEMail" runat="server"></span>
JavaScript на стороне клиента:
<script type="text/javascript">
function validateEMail(source, arguments) {
var isValid;
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "ajax/services.asmx/validateEMail",
data: "{'email': '" + arguments.Value + "'}",
dataType: "json",
async: false,
success: function (result) {
$("#<%=lEMail.ClientID %>").html(result.d.result);
isValid = result.d.valid;
}
});
arguments.IsValid = isValid;
}
</script>
Функция AJAX на стороне сервера:
[WebMethod]
public EMailValidateResult validateEMail(string email)
{
EMailValidateResult result = new EMailValidateResult();
result.valid = false;
result.result = "Invalid...";
if (Regex.IsMatch(email,@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"))
{
result.valid = true;
result.result = "Valid...";
}
else if(check if exists in database)
{ invalid, exists message... }
return result;
}
Обработчик проверки на стороне сервера:
protected void cvEMail_ServerValidate(object source,ServerValidateEventArgs args)
{
args.IsValid = false;
lEMail.InnerHtml = "invalid...";
if(Regex.IsMatch(args.Value,@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"))
{
args.IsValid = true;
lEMail.InnerHtml = "valid...";
}
else if(check if exists in database)
{ invalid, exists message... }
}
Источник: http://brian.dobberteen.com/code/jquery_ajax_custom_validator/