Function not working for onValidate

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!

Hi Shweta,

Try moving the function from the onValidate event to the onComplete event of the form and see if it works correctly,

also, I have noticed a typographical error in your code.
instead of:

return five.sucess(result);

It should be:

return five.success(result);

Let me know if this works

1 Like

Hello,

This worked. Thanks a lot!