Understand on validate actions
The script actions that you define in the on validate event will be executed when a user submits the form to the server before the user data is stored in the database.
Let's assume you have an Employee Management application. In that you have a Leave Request form that the employee uses while updating leaves taken or to be taken. The form includes the employee's name and ID fields, leave type field, date field, and reason field. The leave type field has Sick Leave, Vacation Leave, Personal Leave, On-Duty, and Maternity Leave as options. The Reason field is not mandatory, but you need the employee to fill that field if the selected leave type is On-Duty. You can achieve this by writing a script for on validate event. Your script will state that validate if leave type is On-Duty. If it is selected, display a message saying it is mandatory to enter reason. So while using this form, if the employee selects On-Duty and tries to submit the form without filling the Reason field, the workflow is run and the message stating, "Reason field needs to be filled if the selected leave type is On-Duty," will be displayed.