Assuming this is NOT a Google
Form but is an html "form", all of this is done within either the html file using normal
<script>
javascript
</script>
or within a linked javascript file. You will want to do this in the browser on the client side, not the backend.
You could do your own validation, or use another library (examples:
validate.js &
approvejs show up on a quick Github search) that has already been done for you :)