You can use exit() to stop PHP executing if you need to. Otherwise, you’ll need to validate the form client-side using JavaScript (something you can find plenty of information about here or through Google).
How do I stop form submitting?
The simplest solution to prevent the form submission is to return false on submit event handler defined using the onsubmit property in the HTML