guarda se la prima va bene
codice:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
try
{
string value = args.Value;
if (value.Length != 8) throw new Exception(this.CustomValidator1.ErrorMessage);
DateTime dt = new DateTime(int.Parse(value.Substring(0, 4)), int.Parse(value.Substring(4, 2)), int.Parse(value.Substring(6, 2)));
}
catch (Exception ex)
{
args.IsValid = false;
}
}
protected void CustomValidator2_ServerValidate(object source, ServerValidateEventArgs args)
{
try
{
string value = args.Value;
char[] c = {';'};
string[] s = value.Split(c, StringSplitOptions.RemoveEmptyEntries);
if (s.Length != 3) throw new Exception(this.CustomValidator2.ErrorMessage);
}
catch (Exception ex)
{
args.IsValid = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
this.Validate();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Pagina senza titolo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="Deve essere una data nel formato YYYYMMDD" OnServerValidate="CustomValidator1_ServerValidate" ValidateEmptyText="true"></asp:CustomValidator>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator2" runat="server" ControlToValidate="TextBox2" ErrorMessage="Deve essere tre stringhe alfanumeriche separata da ;" OnServerValidate="CustomValidator2_ServerValidate" ValidateEmptyText="true"></asp:CustomValidator>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /></div>
</form>
</body>
</html>