ASP.NET: Custom client-side validator for "one of two fields must be filled"?

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).

Answers


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.


Oh, sure, about 10 minutes later I found this Code Project article Multiple Fields Validator - An ASP.NET Validation Control by Adam Tibi by myself:


I am not one to push commercial products here but when it comes to asp.net validation you would do yourself an incredible disservice not to take a look at peterblum.com. Best asp.net control package bar none...Hanselmans take on them -

"Not an add-in but rather a complete re-imagining of the ASP.NET Validation Framework. There's a learning curve, but it will change the way you write pages. Also check out his Visual Security Security and Peter'sDatePackage. His documentation is legendary."


Code project also has this control (by yours truly): http://www.codeproject.com/KB/validation/AtLeastOneOfValidator.aspx


Need Your Help

Rust and C compatibility with Visual Studio

c visual-studio rust

Is it possible to create a static library compiled with rustc and link it to an executable compiled with MSVC?

Show empty cell value for datetime field in Kendo grid?

asp.net-mvc-3 datetime kendo-grid

I am using kendo grid where I have added a column of DateTime type which shows datetime.