html表单 提交时对用户名和密码进行验证

来源:互联网 发布:php中字符串的截取 编辑:程序博客网 时间:2024/06/06 18:33

<script language="javascript">function ValidateForm(theForm){ if (theForm.UserName.value.length==0) {  alert("please input the name!")  theForm.UserName.focus();  return(false);  }        if (theForm.password.value.length>=8){    my=document.getElementById('password').value   var re =  /[a-zA-Z](?=.*?[1-9].*?)[a-zA-Z1-9]+|[1-9](?=.*?[a-zA-Z].*?)[a-zA-Z1-9]+/g;      if (!re.test(my))      {  alert("password type error!")       return(false);     }   }     else{  alert("password length error!")  return(false);  }}</script>
对用户名的验证只要求名字长度不为0
对密码的验证要求密码长度大于8,且正则表达式要求必须同时含有字母和数字,否则报错


阅读全文
0 0