Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
Comment

PREVIOUS NEXT
Code Example
Javascript :: focus js 
Javascript :: jquery selected option value 
Javascript :: js copy text to clipboard 
Javascript :: Javascript file in html angeben 
Javascript :: javascript store date in localstorage 
Javascript :: vue router 404 page 
Javascript :: vue select option get attribute 
Javascript :: react state add to array 
Javascript :: how to get back image and front text in react native 
Javascript :: last item in object javascript 
Javascript :: javascript loop through array of objects 
Javascript :: javascript in line logic 
Javascript :: submit form automatically javascript 
Javascript :: move dom element to another parent 
Javascript :: how to cheack if a number is an integer or float in javascript 
Javascript :: javascript falsy values 
Javascript :: js Convert the characters to the html 
Javascript :: copy localstorage javascript 
Javascript :: lazy loading pagination react npm 
Javascript :: javascript create element in a new line 
Javascript :: setinterval break 
Javascript :: import bootstrap css and js file in react 
Javascript :: exit extension from chrome javascript 
Javascript :: javascript switch 
Javascript :: deep copy object/array 
Javascript :: how to check the last item in an array javascript 
Javascript :: javascript delete first character in string 
Javascript :: how to see chrome sync storage and local storage 
Javascript :: localtunnel 
Javascript :: makes number negative javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =