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 :: remove white spaces 
Javascript :: html video autoplay not working 
Javascript :: convert csv to json powershell code 
Javascript :: TypeError: getComputedStyle(...).getPropertyValue is not a function 
Javascript :: vue test form input 
Javascript :: strapi login api 
Javascript :: set stroke color canvas 
Javascript :: js test if string 
Javascript :: add all elements in array javascript 
Javascript :: how to find the last item in a javascript object 
Javascript :: javascript compare two dates 
Javascript :: array from comma separated string javascript 
Javascript :: eslint allow console 
Javascript :: how to check div is display:none or block in javascript 
Javascript :: get the difference between two dates js 
Javascript :: javascript change element id 
Javascript :: ref to another page and achor 
Javascript :: npm express-session 
Javascript :: javascript create a function that counts the number of syllables a word has. each syllable is separated with a dash -. 
Javascript :: js console.log color 
Javascript :: javascript setattribute 
Javascript :: javascript add button to div 
Javascript :: for each python json 
Javascript :: javascript switch statement multiple cases 
Javascript :: Angular Unit Testing: Observable not returning results 
Javascript :: get pods running on a node 
Javascript :: map add key to object in array javascript 
Javascript :: array methods javascript 
Javascript :: select html react 
Javascript :: search if value exists in object javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =