Date check

how did we use data validation on asp.net? date cannot be inserted more than the current date.

+7
c # fluentvalidation
source share
4 answers

Use CompareValidator . Most people use this to compare two values ​​entered in two text fields, but you can also use them to compare one value entered with a given value, as in your case.

<asp:CompareValidator id="Compare1" ControlToValidate="TextBox1" Type="Date" runat="server"/> 

In the code behind Compare1.ValueToCompare = new DateTime(...); and Compare1.Operator = ValidationCompareOperator.LessThanEqual;

In addition, remember: you should always check on the server , as well as on the client, as client verification is easy to disable or bypass. I would suggest you see the Free Confirmation for this.

+2
source share

Using CustomValidator easily solve your problems.

Customvalidator

or

You can use javascript to check your date, as shown below.

 var myDate=new Date(); myDate.setFullYear(2010,0,14); var today = new Date(); if (myDate>today) { alert("Today is before 14th January 2010"); } else { alert("Today is after 14th January 2010"); } 
+1
source share

In javascript solution

Be sure to set hrs, min, secs and milliseconds to 0 if you just want to compare dates (e.g. day, month and year). The function to achieve the above is as follows,

 function f_tcalResetTime (d_date) { d_date.setHours(0); d_date.setMinutes(0); d_date.setSeconds(0); d_date.setMilliseconds(0); return d_date; } 

If you are comparing dates, javascript actually calls the date.valueOf function backstage, which returns the number of milliseconds that have passed since midnight on January 1, 1970.

+1
source share

good meeting. There are many options. You can use asp.net custom validator control, javascript, etc. A better option would be to use an AJAX masked editing editor with a masked rights editor. You can specify ranges, a custom mask (yyyy / MM / dd) and even an empty field message with this.

Just make sure you set your website culture correctly so that you can check the dates correctly. http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/MaskedEdit/MaskedEdit.aspx

Greetings.

 <ajaxToolkit:MaskedEditValidator ControlExtender="MaskedEditExtender2" ControlToValidate="TextBox2" IsValidEmpty="False" MaximumValue="12000" EmptyValueMessage="Number is required" InvalidValueMessage="Number is invalid" MaximumValueMessage="Number > 12000" MinimumValueMessage="Number < -100" MinimumValue="-100" EmptyValueBlurredText="*" InvalidValueBlurredMessage="*" MaximumValueBlurredMessage="*" MinimumValueBlurredText="*" Display="Dynamic" TooltipMessage="Input a number: -100 up to 12.000"/> 
0
source share

All Articles