读书人

用户名跟密码验证

发布时间: 2012-07-01 13:15:00 作者: rapoo

用户名和密码验证
<script type="text/javascript">
function isValidate(form)
{
//取得用户登录信息
username = form.username.value;
userpass = form.userpass.value;

//判断用户名长度
if(!minLength(username,6))
{
alert("用户名长度小于6位!");
form.username.focus();
return false;
}

if(!maxLength(username,8))
{
alert("用户名长度大于8位!");
form.username.focus();
return false;
}

//判断密码长度
if(!minLength(userpass,6))
{
alert("密码长度小于6位!");
form.username.focus();
return false;
}

if(!maxLength(userpass,8))
{
alert("密码长度大于8位!");
form.username.focus();
return false;
}
return true;
}

//验证是否满足最小长度
function minLength(str,length)
{
if(str.length>=length)
return true;
else
return false
}

//验证是否满足最小长度
function maxLength(str,length)
{
if(str.length<=length)
return true;
else
return false
}
</script>


onsubmit="return isValidate(form1)"

读书人网 >Web前端

热点推荐