views:

192

answers:

3

hi

In my page one asp.net Textbox to enter the date.

I need to validate the textbox value ( dd-mmm-yyyy format) should be less than or equal to Current Date using Javascript.

validation using javascript when press on enter button.

A: 

you can use compare validator like ...

<asp:CompareValidator ID="cmv" runat="server" ControlToValidate="txtDate"
 Display="Dynamic" Operator="GreaterThanEqual" SetFocusOnError="True" Type="Date"></asp:CompareValidator>

and in code behind set value to compare today date

cmv.ValueToCompare = DateTime.Now.ToShortDateString()
Muhammad Akhtar
A: 
var myDate1= document.form1.Textbox2.value;

  var date  = myDate1.substring(0,2);
  var month = myDate1.substring(3,5);
  var year  = myDate1.substring(6,10);

  var myDate= new Date(year,month-1,date);

var today = new Date();

if (myDate>today)
  {
  alert("Today is before ");
  }
else
  {
  alert("Today is after ");
  }
Pranay Rana
thank you for help me
jiya gupta
if it help full that atleast do upvote sir
Pranay Rana