87,910
社区成员
发帖
与我相关
我的任务
分享
function checkForm(form)
{
if(!(new RegExp("\\S+")).test(form.userName.value)) { //判断用户名是否为空
alert("请输入用户名!");
form.userName.focus();
return false;
}
if(form.password.value=="" ||(new RegExp("^(\\s*) $")).test(form.password.value)) {//判断密码是否为空
alert("请输入密码 ");
form.password.focus();
return false;
}
return true;
}
<script type="text/javascript">
function checkForm(form){
var reg=/\s+/;
username=form.userName.value;
if(username.length==0){
alert("请输入用户名");
form.userName.focus();
return false;
}else if(reg.test(username)){
alert("请不要输入空格");
return false;
}
var password=form.password.value;
if(password.length==0){
alert("请输入密码 ");
form.password.focus();
return false;
}else if(reg.test(password)){
alert("请不要输入空格");
return false;
}
}
</script>
<script type="text/javascript">
function checkForm(form){
username=form.userName.value;
if(username.length==0){
alert("请输入用户名");
form.userName.focus();
return false;
}
var password=form.password.value;
if(password.length==0){
alert("请输入密码 ");
form.password.focus();
return false;
}
}
</script>