Home  >  Article  >  Backend Development  >  Imitation webQQ designed by php+js+mysql-<2>Other verification_PHP tutorial

Imitation webQQ designed by php+js+mysql-<2>Other verification_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:50:46773browse

Let’s see if other verifications are easy!

<2>Nickname verification

Js code

[javascript]
function checkNickname(Nickname)
{ 
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)

document.getElementById("error2").innerHTML="*"; //Reset
If(Nickname.length==0)
                                                                                            document.getElementById("error2").innerHTML="*The nickname cannot be empty!";
                                                                                                            else  
                                                                           If(Nickname.length>16)
                                                                                                 document.getElementById("error2").innerHTML="*The nickname should not exceed 16 characters!";
                                                                                                                                                                                                                      else                                                                                                  document.getElementById("error2").innerHTML="*Nickname available!";
                                                                                                                                                                                                                                  }  
}
xmlhttp.open("GET","index.php",true);
xmlhttp.send(); //Note the difference between this and email verification
}
function checkNickname(Nickname)
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("error2").innerHTML="*"; //Reset
If(Nickname.length==0)
          {
Document.getElementById("error2").innerHTML="*The nickname cannot be empty!";
}
else
          {
If(Nickname.length>16)
          {
              document.getElementById("error2").innerHTML="*The nickname should not exceed 16 characters!";
}
else
          {
              document.getElementById("error2").innerHTML="*Nickname available!";
}
}
}
}
xmlhttp.open("GET","index.php",true);
xmlhttp.send(); //Note the difference between this and email verification
}


<3>Password verification

Js code

[javascript]
function checkPwd1(password1) 
{    
var xmlhttp; 
if (window.XMLHttpRequest) 
  {// code for IE7+, Firefox, Chrome, Opera, Safari  
    xmlhttp=new XMLHttpRequest(); 
  } 
else 
  {// code for IE6, IE5  
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
  } 
xmlhttp.onreadystatechange=function() 
  { 
  if (xmlhttp.readyState==4 && xmlhttp.status==200) 
    {  document.getElementById("error3").innerHTML="*"; 
       document.getElementById("password2").value=""; 
       document.getElementById("error4").innerHTML="*"; 
       if(password1.length==0) 
          { 
            document.getElementById("error3").innerHTML="*密码不能为空!"; 
             
          } 
       else 
          { 
            if(password1.length<6||password1.length>16) 
               { 
                  document.getElementById("error3").innerHTML="*密码为6-16个字符!"; 
                   
               } 
             else 
               {   
                   var reg=/[a-zA-Z0-9]/;     //在js中使用正则表达式 www.2cto.com   
                   if(reg.test(password1)) 
                      { 
                         document.getElementById("error3").innerHTML="*密码可用!"; 
                       } 
                   else 
                      { 
                         document.getElementById("error3").innerHTML="*密码不可用!"; 
                          
                      }     
               } 
          } 
    } 
  }  
xmlhttp.open("GET","index.php",true); 
xmlhttp.send(); 

function checkPwd1(password1)

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {  document.getElementById("error3").innerHTML="*";
       document.getElementById("password2").value="";
       document.getElementById("error4").innerHTML="*";
    if(password1.length==0)
       {
     document.getElementById("error3").innerHTML="*密码不能为空!";
   
    }
    else
       {
     if(password1.length<6||password1.length>16)
      {
         document.getElementById("error3").innerHTML="*密码为6-16个字符!";
     
      }
    else
      { 
          var reg=/[a-zA-Z0-9]/;     //在js中使用正则表达式
       if(reg.test(password1))
             {
          document.getElementById("error3").innerHTML="*密码可用!";
        }
       else
          {
         document.getElementById("error3").innerHTML="*密码不可用!";
      
       }   
      }
    }
    }
  }
xmlhttp.open("GET","index.php",true);
xmlhttp.send();
}


<4>重复密码验证

Js代码

[javascript]
function checkPwd2(password2) 
{    
var xmlhttp; 
if (window.XMLHttpRequest) 
  {// code for IE7+, Firefox, Chrome, Opera, Safari  
    xmlhttp=new XMLHttpRequest(); 
  } 
else 
  {// code for IE6, IE5  
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
  } 
xmlhttp.onreadystatechange=function() 
  { 
  if (xmlhttp.readyState==4 && xmlhttp.status==200) 
    {  document.getElementById("error4").innerHTML="*"; 
       if(password2.length==0) 
          { 
            document.getElementById("error4").innerHTML="*请确认密码!"; 
             
          } 
       else 
          { 
            if(password2!=document.getElementById("password1").value) 
               { 
                  document.getElementById("error4").innerHTML="*两次密码输入不一致!"; 
                   
               } 
            else  
               { 
                  document.getElementById("error4").innerHTML="*密码输入一致!"; 
               } 
             
          } 
    } 
  }  
xmlhttp.open("GET","index.php",true); 
xmlhttp.send(); 

function checkPwd2(password2)

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {  document.getElementById("error4").innerHTML="*";
    if(password2.length==0)
       {
     document.getElementById("error4").innerHTML="*请确认密码!";
   
    }
    else
       {
     if(password2!=document.getElementById("password1").value)
      {
         document.getElementById("error4").innerHTML="*两次密码输入不一致!";
     
      }
   else
      {
      document.getElementById("error4").innerHTML="*密码输入一致!";
      }
   
    }
    }
  }
xmlhttp.open("GET","index.php",true);
xmlhttp.send();
}


How about it, it’s quite simple! (To be continued)

Excerpted from wyzhangchengjin123

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478249.htmlTechArticleLet’s see if other verifications are very simple! 2 Nickname verification Js code [javascript] function checkNickname(Nickname) { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefo...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn