Validate date for anyone over 18 with jQuery

前端 未结 6 2085
借酒劲吻你
借酒劲吻你 2021-01-18 03:07

I have a form on my site that should validate for anyone who is over 18.

var day = $(\"#dobDay\").val();
var month = $(\"#dobMonth\").val();
var year = $(\"         


        
6条回答
  •  伪装坚强ぢ
    2021-01-18 03:47

    check this DEMO

    var day = 12;
    var month = 12;
    var year = 2006;
    var age = 18;
    var setDate = new Date(year + age, month - 1, day);
    var currdate = new Date();
    
    if (currdate >= setDate) {
      // you are above 18
      alert("above 18");
    } else {
      alert("below 18");
    }

提交回复
热议问题