3

I have start date and end date, start date should be greater than end date.

I have two more date pickers discount start date and discount end date.

Discount start date should be less than start date and discount end date should be less than end date. How to write validations in Javascript or jQuery?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
karthik
  • 57
  • 6

1 Answers1

1

You didn't gave any info about the date foramt anyway the logic is always the same like:

var date,endDate,dateDiscount,endDateDiscount;
if ((date<=endDate) || (dateDiscount>=date) || (endDateDiscount>=endDate)) alert('error! dates not good')

explain:

(date<=endDate) //the reverse of "start date should be greater than end date"
(dateDiscount>=date) //the reverse of "discount start date should be less than start date"
(endDateDiscount>=endDate) // the reverse of "discount end date should be less than end date "
Amir Bar
  • 3,007
  • 2
  • 29
  • 47
  • After checking the validations of start date and end date can we write like this.if ((date<=endDate) { (dateDiscount>=date) || (endDateDiscount>=endDate))} alert('error! dates not good') – karthik Aug 03 '15 at 04:37