How can I validate that someone is over 18 from their date of birth?

后端 未结 6 1190
一向
一向 2020-12-31 16:47

I am doing validation for Driver\'s Date of birth, it should be minimum of 18 from the current date.

var Dates = $get(\'<%=ui_txtDOB.ClientID %>\');            


        
6条回答
  •  失恋的感觉
    2020-12-31 17:25

    let TODAY = new Date(Date.now());
    let EIGHTEEN_YEARS_BACK = new Date(new Date(TODAY).getDate() + "/" + new Date(TODAY).getMonth() + "/" + (new Date(TODAY).getFullYear() - 18));
    let USER_INPUT = new Date("2003/12/13");
    // Validate Now
    let result = EIGHTEEN_YEARS_BACK > USER_INPUT // true if over 18, false if less than 18
    

    I think this is the closest possible way to check.

提交回复
热议问题