[Vuejs]-Vue js & validate DOB is within a range?

0👍

import * as moment from "moment";

let birthday = moment(moment.now()).diff(moment(this.user.day + this.user.month + this.user.year, "DD.MM.YYYY"),"years");
if(birthday > 21 && birthday < 55) {
  // do next steps
}

Moment(npm install moment) is used to parse, manipulate & display dates and times in JavaScript. moment.now() will give the present date and assuming you have three fields for day, month and year in different variables, format it and use the diff function to find the age.

0👍

The example from Madhuri works for me but i change the input as hard coded string.

enter code here let birthday = moment(moment.now()).diff(moment('01.01.1990', "DD.MM.YYYY"), "years");
          if(birthday >= 20 && birthday <=70 ){
            return birthday;
          }
        }

0👍

I solved it with with value from form input which works for me.

checkBirthday(){
          const birthDayDate = document.getElementById("birthdate").value;
          const age = moment().diff(birthDayDate, "years");
          // let birthday = moment(moment.now()).diff(moment('01.01.1990', "DD.MM.YYYY"), "years");
          if(age >= 18 && age <=74 ){
            return age;
          }
        },

Leave a comment