Validate date for anyone over 18 with jQuery

前端 未结 6 2122
借酒劲吻你
借酒劲吻你 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 04:00

    I think it will be easier to understand if we rename the variables

    mydate => givenDate
    currdate => thresholdDate

    if givenDate > thresholdDate => you are not 18
    else => you are 18

    i.e.

    if ( givenDate > thresholdDate ){
        // you are not 18
    }
    

    i.e

    if ((givenDate - thresholdDate) > 0){
        // you are not 18
    }
    

    i.e.

    if ((mydate - currdate ) > 0){
        // you are not 18
    }
    

提交回复
热议问题