Answers for "date of birth greater 18 year and less 58 year validation js"

1

date of birth validation for 18 years javascript

function isOver18(dateOfBirth) {
  // find the date 18 years ago
  const date18YrsAgo = new Date();
  date18YrsAgo.setFullYear(date18YrsAgo.getFullYear() - 18);
  // check if the date of birth is before that date
  return dateOfBirth <= date18YrsAgo;
}

isOver18(new Date("1999-12-01")); // true
isOver18(new Date("2020-03-27")); // false
Posted by: Guest on June-02-2021
0

Is date greater than 18 years old javascript

function isDate18orMoreYearsOld(day, month, year) {
    return new Date(year+18, month-1, day) <= new Date();
}
Posted by: Guest on April-21-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language