Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

validate age 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 :: remove white space from string in js 
Javascript :: nodejs get all folders in directory 
Javascript :: get the value or text from select element using javaScript 
Javascript :: How to fix stomp websocket error 
Javascript :: remove text javascript 
Javascript :: push state array react 
Javascript :: calling javascript functions from unity scripts 
Javascript :: javascript add new line in string 
Javascript :: summation of array elements 
Javascript :: get the last item in object javascript 
Javascript :: compare dates in js 
Javascript :: express start template 
Javascript :: double question mark javascript 
Javascript :: react native open link in browser 
Javascript :: rounding off in javascript 
Javascript :: number validation in javascript 
Javascript :: link to another page and achor 
Javascript :: unhandledpromiserejectionwarning: mongooseerror: the `uri` parameter to `openuri()` must be a string, got "undefined". 
Javascript :: change url with javascript after 5 seconds 
Javascript :: chart js two y axis 
Javascript :: style react background 
Javascript :: digit count in javascript 
Javascript :: today in moment 
Javascript :: firebase storage javascript delete document 
Javascript :: convert class object to json node js 
Javascript :: getcollectionnames 
Javascript :: javascript forever loop 
Javascript :: query select multiple classes 
Javascript :: how to return json response in flask 
Javascript :: print hello world in javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =