So I have this OPTIONAL field in my application form which is a Filename for an xml file, but since it is optional I just need it to apply the regular expression validation ONLY WHEN SOMETHING IS TYPED, otherwise if its empty don't apply it and let the user proceed without specifying the Filename.
<asp:TextBox id="tbxmlFile" runat="server" Width="100px"></asp:TextBox>
<asp:regularexpressionvalidator id="regular2" Display="Dynamic" controltovalidate="tbxmlFile" runat="server" errormessage='"Filename must only contain letters and numbers and end in .xml' validationexpression='([a-zA-Z0-9\s\.])+(.xml)$' ForeColor="Red"></asp:regularexpressionvalidator>
Is there any regular expression that let me do this? or is there any way to insert the regularexoressionvalidator from the VB backend if the string of the textbox is empty? Thanks for your answers
The following is the regex im using: ([a-zA-Z0-9\s.])+(.xml)$