Show a simplified version of what doesn't work for you.
Does not need to be the whole script, just a sample of what seems to be the problem in your code.
What does your <form> tag look like?
May be as simple as
<form id="myForm" action="???" method="post" onsubmit="return validationCode()">
where "validationCode()" function returns true or false depending on results of validation.