How ASP. NET verifies the date in the YYYY-MM-DD format

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.