Client-side validation for two separate conditions
<p>Is there a way to validate asp.net text box for input using built-in validators for two distinct conditions? The text box is used in conjunction with a date picker and presently I have RegularExpressionValidator like this to validate:</p>

<pre><code>&lt;asp:TextBox ID="tbStartDate" runat="server" Width="100" CssClass="TextCompact"&gt;yyyy&lt;/asp:TextBox&gt;
&lt;asp:HyperLink ID="hlStartDate" runat="server" ImageUrl="~/Images/iconCalendar.gif"&gt;&lt;/asp:HyperLink&gt;&lt;br /&gt;
&lt;asp:RegularExpressionValidator ID="revStartDate" ControlToValidate="tbStartDate"
     CssClass="TextCompact" runat="server" ErrorMessage="* Invalid Date" ValidationExpression="^(\d{4})$" /&gt;
</code></pre>

<p>which fires everytime an invalid date is entered - you can use the date picker or you can type in a date string.</p>

<p>So the issue is that I only want to validate if there is data in the text box. If the text box is empty I want it to pass through without validation.</p>

<p>Is this possible or would a custom client side validation be required?</p>

<p>Thanks,
Risho.</p>

<p>Update:</p>

<p>I've decided to write my own validator class derived from the BaseValidator class and wired it up but I get a compiler error.</p>

<pre><code>namespace Abcdefg1234
{
    public class Custom_Validator : BaseValidator
    {
        public Custom_Validator()
        {

        }

        protected override bool EvaluateIsValid()
        {
            String value = this.GetControlValidationValue(this.ControlToValidate);
            return ValidateControls(value.Trim());
        }

        public static bool ValidateControls(string value)
        {

            if(Regex.IsMatch(value, @"^(\d{4})$") == true)
                return true;
            else if(value == "")
                return true;
            else
                return false;
        }
    }
}
</code></pre>

<p>Then I included the page directive tag:</p>

<pre><code>&lt;%@ Register TagPrefix="Cv" Namespace="Abcdefg1234" TagName="CustomValidaitonX" %&gt;
</code></pre>

<p>and the actual tag:</p>

<pre><code>Cv:Custom_Validator ID="cvtbStartDate" ControlToValidate="tbStartDate"                        runat="server" ErrorMessage="* Invalid Date" /&gt;
</code></pre>

<p>I get a unknown server tag. Any ideas? Thanks.</p>
