try this:
<script type = "text/javascript">
function checkField(fieldname)
{
if (/[^0-9a-bA-B\s]/gi.test(fieldname.value))
{
alert ("Only alphanumeric characters and spaces are valid in this field");
fieldname.value = "";
fieldname.focus();
return false;
}
}
</script>
and call it like this:
<input type="text" name="name" id="name" onblur="checkField(this)">