Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

check if over 18 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 :: js replace characters in a string 
Javascript :: js get date from datetime 
Javascript :: javascript empty cache and hard reload 
Javascript :: Uncaught Error: Incompatibile SockJS! Main site uses: "1.0.2", the iframe: "1.0.0". 
Javascript :: javascript open new tab window 
Javascript :: convert iso 8601 to utc javascript 
Javascript :: port 3000 is already in use nodemon app crashed 
Javascript :: js string check case 
Javascript :: sum javascript 
Javascript :: load a page with ajax 
Javascript :: react image 
Javascript :: first digit javascript 
Javascript :: javascript regex extract url from string 
Javascript :: javascript reverse array 
Javascript :: search content in js 
Javascript :: react native get navigation bar height 
Javascript :: navigate-to-an-anchor-on-another-page 
Javascript :: how to install nodejs on arch linux 
Javascript :: js change button text 
Javascript :: js enter key event listener 
Javascript :: jquery change text color 
Javascript :: how to redirect to another page in javascript on submit type 
Javascript :: moment to date 
Javascript :: autocomplete react vscode 
Javascript :: how to check if radio button is checked javascript 
Javascript :: express redirect to url 
Javascript :: json get key 
Javascript :: get element with one or another class 
Javascript :: get all the properties of a object in javascript 
Javascript :: how to iterate object inside object in javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =