I’ve been using Enterprise Library and Property Proxy Validators to do some validation for the web search form I’m developing. The form has a few fields relevant to a person that are optional to search on, however there is a minimum to search on either Last Name or SSN.
In the RuleSet I setup for the search none of the Validators seem to really give the ability to handle checking for atleast 1 not null. The way I got around this was setup however you want your validators to be for regular data. Make sure that the empty string case can be successful either in your regular expressions or add a String Lenght Validator LowerBound 0 Upperbound 0 inside an OR composite validator along with the rest of your validations.
Currently this setup will give you pass for all nulls, the way I overcame this was to setup a Property Comparison Validator inside an And Composition Validator on my Last Name field having it compare to the SSN field set to NOT Equal. Which gives us a truth table similiar to:
LastName: “Smith” Pass – SSN: “123%” Pass – Overall Pass
LastName: “” Pass – SSN: “123%” Pass – Overall Pass
LastName: “Smith” Pass – SSN: “” Pass – Overall Pass
LastName: “” Pass – SSN: “” Pass – Overall FAIL which is what we want to happen.
There’s only one slight caveat to doing it this, entering exact same values with real text into the last name field and SSN field will generate the case that we have set for nulls.
LastName “123%” Fail – SSN “123%” Pass – Overall FAIL.
Overall i think this is an acceptable trade off, especially with the vastly different validation types. Now if you were going to use this method to compare First Name and Last Name, you would need to weigh if it would be worth making it impossible to search for a person with the same first name as last name. Of course if the search handles wild cards it could easily be worked around with just an explanation to take off 1 letter.
One last thing I needed to figure out was how to stop the property proxy validators from firing when I hit my reset button because it sets it to an valid state making every field null (not suprising since we just set the fields not accept all nulls). Maybe this more obvious to others or perhaps people that have just worked more using ASP.NET’s page validation but the only thing needed done to fix this was add to my button
<asp:button id=”btnReset” runat=”server” On_Click=”btnReset_Click” CausesValidation=”false” />