JavaScript file (script.js):
When the user clicks the submit button on the HTML page, the validateForm() function is called and the input fields are checked for errors. If there are errors, the function returns "false" and displays an error message on the page. If there are no errors, the function returns "true" and submits the form to the server for further processing.
Note that this is a basic example of form validation using JavaScript. In a real-world application, you would also need to validate user input on the server side to prevent security vulnerabilities such as SQL injection and cross-site scripting (XSS) attacks.