Web app for desktop and mobile in javascript

When saving a recored I want to call a vfp function via lianja.evaluate to check data before a save and not allow the save if the function returns false.

I want to use a vfp function, as I already have the code in a prg in my old app, on the database itself or perhaps in meta data so that I don't have to code it in the page itself and have code all over the place

My question is what is the best way to inform the user that the save could not be done.

For example adding and animal to my system and part of the data is the animals parents fk. Function would check if the animals birth date is after that of the parent and if the same or before inform the user that "The record could not be saved as animals birth date if before mothers birth date".

In the web I understand that the UI knows nothing about the backend and vice versa, so what's the best way to display this message in the UI to the user from code on the backend?