很简单的一个例子
function checkForm(){
var reg = new RegExp("^[A-Za-z0-9] $");
if(!reg.test(form1.name.value)){
alert("用户名只能由字母和数字组成");
form1.name.value = "";
form1.pwd.value = "";
form1.name.focus();
return false;
}
return true;
}
function regist(){
if(checkForm()){
with(document.getElementById("form1")){
method = "post";
action = "user/regist";
submit();
}
}
}