Method One:
Date format YYYY-MM-DD
<asp:rangevalidator id= "vldrngdate" runat= "Server" cssclass= "main" errormessage= "date must be between 1900~2500" Controltov Alidate= "Txtdate" display= "None" minimumvalue= "1900-01-01" maximumvalue= "2500-12-31" type= "Date" ></asp:range Validator>
Method Two:
Verify whether it is empty
<asp:requiredfieldvalidator id= "RequiredFieldValidator1" runat= "Server" errormessage= "RequiredFieldValidator" D Isplay= "Dynamic" controltovalidate= "TextBox" ></asp:RequiredFieldValidator>
Toolbox---> select comparevalidator-->controltovalidate for the input box that needs validation-->operatoe for the way you want to verify-->type for the type you need to verify
Verifies whether the date format is
<asp:comparevalidator id= "CompareValidator1" runat= "Server" errormessage= "CompareValidator" display= "Dynamic" Controltovalidate= "TextBox" operator= "DataTypeCheck" type= "Date" ></asp:CompareValidator>
Method Three:
Regular expressions
Error warning and allow focus to leave:
<asp:TextBox>< id= "TextBox1" Onchange= "Validatedatatype (' Date ')" runat=server>
</asp:TextBox>
An error warning does not allow focus to leave:
<asp:TextBox>< id= "TextBox1" Onblur= "Validatedatatype (' Date ')" runat=server>
</asp:TextBox>
<JavaScript>
function Validatedatatype (strdatatype)
{
var Reg;
var sexample
if (Strdatatype.match ("Curr"))
{
Reg =/^ (\+|-)? \d+ (, \d\d\d) * (\.\d*)? $/g;//deal as Double
Sexample = "\n123 +123-123\n23456.78-23456.78\n23,456.78-23,456.78\n0.12-0.12\n.12-.12\n0 +0-0 ";
}
else if (Strdatatype.match ("Date"))
{
Reg =/^ ([1-2]\d{3}) (-|\.) (0?) [1-9]|10|11|12) (-|\.) ([0-2]? [1-9]) | 10|20|30|31) $/g;
Sexample = "\n2003-08-24 2003.08.24\n1998-12-1 1998.12.1";
}
else if (Strdatatype.match ("Doub"))
{
Reg =/^ (\+|-)? \d+ (, \d\d\d) * (\.\d*)? $/g;
Sexample = "\n123 +123-123\n23456.78-23456.78\n23,456.78-23,456.78\n0.12-0.12\n.12-.12\n0 +0-0 ";
}
else if (Strdatatype.match ("Int"))
{
Reg =/^ (\+|-)? \d+ (, \d\d\d) *$/g;
Sexample = "\n23456 +23456-23456\n23,456-23,456\n0 +0-0";
}
Else
{
Reg =/^.*$/g;
sexample = "[Email protected]#$%^&* () _+,./; ':";
}
var e = window.event.srcElement;
var str = E.value.trim ();
if (str = = "") return;
if (Reg.exec (str)) return;
Alert ("Error:the value [" + str + "] does not fit with the data type [" + S Trdatatype + "]."
+ "\n\nyou may follow these formats:" + sexample);
E.focus ();
}
</JavaScript>
How ASP. NET verifies the date in the YYYY-MM-DD format