I want to check if the user enters alphabet or numbers only in the
text box. If the user enters non-alphabet or non-numbers, I should pop
up a message and doesn't allow the user to do that. I am using regular
expression to do the checking. But it seems it always return false.
What did I miss? please advise. thanks!!
<script type="text/javascript">
function checkkey(obj)
{ var re = /^[a-zA-Z_0-9]$/;
alert(re.test(obj.value));
if (! re.test(obj.value))
{ alert("Please enter alphanumeric only");
}
}
</script>
<form name="InputForm">
<P><input type="text" name="username"
onKeyPress="checkkey(InputForm.username)">
</form>