It's pretty easy:
I can't provide the exact syntax since I don't remember it and I'd have to look it up
But I can provide you with what you need to do.
1) instead of having a submit button, have a regular button that's just labeled submit, and have the onclick point to a javascript function.
2) this javascript function will
-check that the input is valid
--if valid, call document.formname.submit() *or something to this effect*
--if invalid, show a dialog box telling the user of the error.