Question

reg age

Hi Team,

I attempted to keep a validation on Date of Birth,i need a condition where if we select date of birth below 18 then it should show a prompt ,

I tried this by using java script

Code:



function calculateAge() {

var seldate = document.getElementById("childrenAge").value;

dt1 = new Date(); //today date

dt2 = new Date(seldate); //selected date

var age =diff_years(dt1, dt2);

if(age<18){

alert("please select date more than or equals to 18");

document.getElementById("childrenAge").value =""

}

}

function diff_years(dt1, dt2)

{

 var diff =(dt2.getTime() - dt1.getTime()) / 1000;

  diff /= (60 * 60 * 24);

 return Math.abs(Math.round(diff/365.25));

 

}

 

Can u please send me the code in require js.

Hoping for a positive reply.

Like 0

Like

0 comments
Show all comments