Adding this code to the form didn't work

I copied this code, which successfully makes entering an email into my form mandatory, tweaked it slightly, hoping it would be enough to make adding a Contact Name mandatory, but it didn’t work. What am I missing? You guidance will be appreciated. Thanks


<script type="text/javascript">
function checkcontact(){
var str=document.myform.contact_name.value;
var filter=/^([\\w-]+(?:\\.[\\w-]+)*)((?:[\\w-]+\\.)*\\w[\\w-]{0,66})\\.([a-z]{2,6}(?:\\.[a-z]{2})?)$/i;
if(filter.test(str))
testresults=true;
else {
alert("Please input a valid contact name");
return false;
}
</script>

Where are you calling the function checkcontact() from?

Also you should be aware that alert() is only useful now for debugging as it displays additional checkboxes either for turning off alert dialogs or turning off JavaScript.

Thanks for your reply. I currently have this in my Form:

<form action=‘form_handle.php’ method=‘post’ name=‘myform’ onSubmit=“return checkemail()”>

Should I add this:
<form action=‘form_handle.php’ method=‘post’ name=‘myform’ onSubmit=“return checkcontact()”>

Also, I don’t know what you mean by:
“Also you should be aware that alert() is only useful now for debugging as it displays additional checkboxes either for turning off alert dialogs or turning off JavaScript.”
Could you please clarify?
Thanks again