Can you tell me if there anybody has implemented a custom validator for checking that one of two (or N) input fields are filled?
"Insert phone number or email address"
I'm using ASP.NET (Ajax) 3.5, the ajaxToolkit:ValidatorCalloutExtender (and jQuery if it's necessary).
I just did this (requires jQuery):
JS:
function validatePhoneOrEmail(source, args) {
if ($("[id$='txtEmail']").val() == "" && $("[id$='txtTel']").val() == "")
args.IsValid = false;
else
args.IsValid = true;
}
ASP.NET:
<asp:CustomValidator runat="server"
ClientValidationFunction="validatePhoneOrEmail"
ErrorMessage="Please enter a telephone number or email address">
</asp:CustomValidator>
I don't have any server-side validation for this, but I'm assuming a similar function in the server would be pretty easy to create.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With