bouncer icon indicating copy to clipboard operation
bouncer copied to clipboard

Age Validation

Open nathanaskinner opened this issue 4 years ago • 0 comments

We use a three field style Date of Birth pattern with a month select, day input, and year input.

I have a Javascript function to validate the age > 5 , < 110 (see below);

validateAge(year,month,day) {

    const max_year = new Date().getFullYear() - 110 ;
    const min_year = new Date().getFullYear() - 5 ;
    const _month = new Date().getMonth() + 1;
    const _day = new Date().getDay();

    const dateofbirthDate = new Date(year + "-"+month+"-"+day);
    const mindate = new Date( min_year+ '-'+_month+'-'+_day);
    const maxdate = new Date(max_year+ '-'+_month+'-'+_day);


    if(dateofbirthDate <= mindate && dateofbirthDate >= maxdate){
        return true;
    }
    else
        return false; 
}

We use bouncer for our validation, but how would I/could I incorporate this in to bouncer with customValidations?

nathanaskinner avatar Nov 10 '20 17:11 nathanaskinner