how we used data validation on asp.net? date can't be insert greater than the current date.
Make use of the CustomValidator
will resolve your issues easily.
or
You can use javascript to validate your date like as following
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");
}
Use a CompareValidator. Most people use this for comparing two values entered into two textboxes, but you can also use it to compare one entered value with a set value as in your case.
<asp:CompareValidator id="Compare1"
ControlToValidate="TextBox1"
Type="Date"
runat="server"/>
In the code behind set Compare1.ValueToCompare = new DateTime(...);
and Compare1.Operator = ValidationCompareOperator.LessThanEqual;
Also, Remember: You should always validate on the Server as well as the client, because clientside validation is easy to switch off or by-passed. I would suggest you look at Fluent validation for this.
In javascript solution,
Make sure to set hrs, min, secs, and milliseconds to 0, if you just want to compare dates (i.e day,month and year). Function to acheive the above mentioned 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 compare dates, javascript actually call date.valueOf function behind the scenes, which returns the number of millisecond passed since midnight January 1, 1970.
Hello, good date mate. There are many options available. You can either use asp.net's custom validator control, javascript etc. A better option would be to use AJAX control toolkit's masked edit extender with masked edit validator. You can specify ranges, custom mask (yyyy/MM/dd) and even an empty field message with that.
Just make sure you set the culture of your website right so that you can validate dates properly. http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/MaskedEdit/MaskedEdit.aspx
Cheers.
<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"/>