Validate that end date is greater than start date with jQuery

前端 未结 15 1946
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 13:14

How do I check/validate in jQuery whether end date [textbox] is greater than start date [textbox]?

15条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 13:28

    First you split the values of two input box by using split function. then concat the same in reverse order. after concat nation parse it to integer. then compare two values in in if statement. eg.1>20-11-2018 2>21-11-2018

    after split and concat new values for comparison 20181120 and 20181121 the after that compare the same.

    var date1 = $('#datevalue1').val();
    var date2 = $('#datevalue2').val();
    var d1 = date1.split("-");
    var d2 = date2.split("-");
    
    d1 = d1[2].concat(d1[1], d1[0]);
    d2 = d2[2].concat(d2[1], d2[0]);
    
    if (parseInt(d1) > parseInt(d2)) {
    
        $('#fromdatepicker').val('');
    } else {
    
    }
    

提交回复
热议问题