1. 程式人生 > >檢查密碼和確認密碼的JavaScript

檢查密碼和確認密碼的JavaScript

function checkPassword()
 {
  if(document.getElementById("password").value==null||document.getElementById("password").value=="")
  {
   document.getElementById("spanPassword").innerHTML = "<font color='red'>請輸入密碼 *</font>";
   return false;
  }
  document.getElementById("spanPassword").innerHTML = "<font color='red'>*</font>";
 }
 
 function checkPasswordConfig()
 {
  var a=document.getElementById("password").value;
  var b=document.getElementById("passwordConfig").value;
  
  if(b==null||b=="")
  {
   document.getElementById("spanPasswordConfig").innerHTML = "<font color='red'>請您確認密碼! *</font>";
   return false;
  }
  if(a!=b)
  {
   document.getElementById("spanPasswordConfig").innerHTML = "<font color='red'>您兩次輸入的密碼不一致! *</font>";
   return false;
  }
  
  document.getElementById("spanPasswordConfig").innerHTML = "<font color='red'>*</font>";
 }