Prevent spam registration checking if the submit button is clicked

I am trying to achieve something on registration page. Using login_footer action hook I am adding following script:

<script>
const element = document.getElementById('wp-submit')
element.addEventListener("click", () => {
    alert('hello');
});
</script>

As you can see, this is checking if the submit button is clicked. Now, what I want is: if the submit button is clicked, it’s okay; otherwise registration form won’t be submitted.

How can I achieve that.
Thanks in advance.