Check result of ASP.Net validator clientside
Posted
by
Steffen
on Stack Overflow
See other posts from Stack Overflow
or by Steffen
Published on 2010-12-28T14:26:22Z
Indexed on
2010/12/28
14:54 UTC
Read the original article
Hit count: 177
I know the built-in ASP.Net validators come with a client-side framework, however I've been unable to find anything that lets me check a single validator for it's Valid state.
I expect it to be possible though, so I hope someone in here knows how to do it :-)
The validator in question is a RegularExpressionValidator, which I use to determine whether an e-mail address is valid or not.
Here's some brief code:
<script>
function CheckForExistingEmail()
{
Page_ClientValidate(); // Ensure client validation
if (revEmail.IsValid) // pseudo code!
{
// Perform server side lookup in DB for whether the e-mail exists.
}
}
</script>
<asp:TextBox runat="server" id="tbEmail" onblur="CheckForExistingEmail();" />
<asp:RegularExpressionValidator id="revEmail" runat="server" ControlToValidate="tbEmail" ErrorMessage="Not a valid e-mail address" ValidationExpression="([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})" />
© Stack Overflow or respective owner