Forms have a lot of built-in functionality. If you turn the content of the modal into a form, add required to the input fields, and change the email field to type="email", you can skip custom validation and just use the browser's built-in validation.

However, it should be noted that this doesn't always align well with the design, but it's at least an option.