日期:2014-05-16  浏览次数:20364 次

自己写的js验证例子,不满足条件时会有文字提示的!不用alert!

<script type="text/javascript">





function check(obj){
if(obj.value.length < 6 || obj.value.length > 16) {

document.getElementById("errorinfo").style.display = "block";
document.getElementById("submit").disabled = true;
}
 
 
 
  else {
 
  document.getElementById("errorinfo").style.display = "none";
  document.getElementById("submit").disabled = false; 
  }
 
 
   
}
function checkPwd(obj)
{
  if (obj.value.length < 6 || obj.value.length > 16) {
  document.getElementById("errorpwd").style.display = "block";
  document.getElementById("submit").disabled = true;
 
 
 
  }
  else {
 
  document.getElementById("errorpwd").style.display = "none";
  document.getElementById("submit").disabled = false;
 
  }
 
   
}
function checkRePwd(obj)
{
  var p=document.getElementById("password");
  if(obj.value.length<6||obj.value.length>16)
  {
     document.getElementById("errorrepwd1").style.display = "block";
      document.getElementById("submit").disabled = true;
    
   

  }
  if (p.value != obj.value) {
  document.getElementById("errorrepwd2").style.display = "block";
  document.getElementById("submit").disabled = true;
 
 
 
  }
  else {
    document.getElementById("errorrepwd1").style.display = "none";
  document.getElementById("errorrepwd2").style.display = "none";
  document.getElementById("submit").disabled = false;
 
  }
 
   
}
function checkemail(obj)
{
var cEmail=obj.value;

if(cEmail.match(/[\w-]+@{1}[\w-]+\.{1}\w{2,4}(\.{0,1}\w{2}){0,1}/ig)!=cEmail){
  document.getElementById("erroremail").style.display = "block";
   document.getElementById("submit").disabled = true;
 
  }
else{
  document.getElementById("erroremail").style.display = "none";
   document.getElementById("submit").disabled = false;
 
  }


 
   
}
function checkqq(obj){
var q=obj.value;
var filter=/^\s*[.0-9]{5,10}\s*$/;
    if(!filter.test(q)){
    document.getElementById("errorqq").style.display = "block";
    }else{
    document.getElementById("errorqq").style.display = "none";
   

}
}


</script>






<link href="<%=request.getContextPath()%>/style.css" rel="stylesheet" type="text/css">
</head>

<body bgcolor="#CCCCCC"  >
<p style="color:#FF0000" align="center">温馨提示:带&quot;*&quot;为必填内容</p>

<form name="form1" method="post" action="servlet/RegisterServlet" >
  <table width="41%" height="300" border="0" align="center" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
    <tr bgcolor="#FFFFFF">
      <td height="27" colspan="2" align="center" background="images/table.gif">&l