<script>
function check(frm){
if(!/^[\w._-]{4,20}$/.test(frm.username.value)){
alert("username [4,20]");frm.username.select();return false;
}
if(!/^\w{8,16}$/.test(frm.pwd.value)){
alert("pwd [8,16]");frm.pwd.select();return false;
}
return true;
}
</script>
<form action=ok.aspx onsubmit='return check(this)'>
<input name=username>
<input type=password name=pwd>
<input type=submit value=submit>
</form>