jiya gupta
jiya gupta

Reputation: 109

How to validate one date from current date in javascript?

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.

Upvotes: 2

Views: 9381

Answers (1)

Pranay Rana
Pranay Rana

Reputation: 176956

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 ");
  }

Upvotes: 3

Related Questions