I want that person should be at least 5 days old, so I created a function for that and added it to onValidate event. But I am not getting any error if I entered wrong date.
This is the function I wrote
This is the form field.
This is function added to event.
I have tried using two code
1.
const date = new Date(five.field.DateOfBirth);
let diffInMilliseconds = new Date() - date;
let diffInDays = diffInMilliseconds / (1000 * 60 * 60 * 24);
if(diffInDays < 5){
return five.createError(result, 'Needs to be atleast 5 days old');
}
return five.sucess(result);
}
function CheckBirthDate(sender, context, result) {
const date = new Date(sender.value);
let diffInMilliseconds = new Date() - date;
let diffInDays = diffInMilliseconds / (1000 * 60 * 60 * 24);
if(diffInDays < 5){
return five.createError(result, 'Needs to be atleast 5 days old');
}
return five.sucess(result);
}
Both did not work. What am I doing wrong? Can someone help, please
Thanks!