Check the result of working with ASP.Net validator certificate

I know that ASP.Net built-in validators come with a client base, but I could not find anything that allows me to check one validator for it. Valid condition.

I expect this to be possible, so I hope someone here knows how to do this :-)

The validator in question is the RegularExpressionValidator, which I use to determine if the email address is valid.

Here is a short 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})" /> 
+4
source share
2 answers

Now I have found a way around me:

By adding a ValidationGroup to the validator, I can use Page_ClientValidate (validationgroup) - which returns the value of bool.

I'm not sure if this was the same thing you had in mind Pabuc, if it were, please drop the answer and I will obviously choose it as the correct one :-)

Here is the code that works:

 <script> function CheckForExistingEmail() { if(Page_ClientValidate("email")) { // 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" ValidationGroup="email" 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})" /> 
+6
source

You can look at the visibility of the Validator message (usually we have a red Asterisk *)

 if (document.getElementById("ctl00_ContentPlaceHolder1_revClientSite").style.visibility == "hidden") { // validator says go ahead } else { alert("please fix the indicated field - it is not valid"); } 

.style.visibility will be "hidden" or "visible"

+1
source

Source: https://habr.com/ru/post/1333575/


All Articles