php+js+mysql設計の擬webQQ-<2>その他の検証
4025 ワード
他の検証が簡単かどうか見てみましょう.
<2>ニックネーム検証
Jsコード
Jsコード
Jsコード
<2>ニックネーム検証
Jsコード
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="<font color=red size=2px>*</font>"; //
if(Nickname.length==0)
{
document.getElementById("error2").innerHTML="<font color=red size=2px>* !</font>";
}
else
{
if(Nickname.length>16)
{
document.getElementById("error2").innerHTML="<font color=red size=2px>* 16 !</font>";
}
else
{
document.getElementById("error2").innerHTML="<font color=green size=2px>* !</font>";
}
}
}
}
xmlhttp.open("GET","index.php",true);
xmlhttp.send(); //
}
<3>パスワード検証Jsコード
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="<font color=red size=2px>*</font>";
document.getElementById("password2").value="";
document.getElementById("error4").innerHTML="<font color=red size=2px>*</font>";
if(password1.length==0)
{
document.getElementById("error3").innerHTML="<font color=red size=2px>* !</font>";
}
else
{
if(password1.length<6||password1.length>16)
{
document.getElementById("error3").innerHTML="<font color=red size=2px>* 6-16 !</font>";
}
else
{
var reg=/[a-zA-Z0-9]/; // js
if(reg.test(password1))
{
document.getElementById("error3").innerHTML="<font color=green size=2px>* !</font>";
}
else
{
document.getElementById("error3").innerHTML="<font color=red size=2px>* !</font>";
}
}
}
}
}
xmlhttp.open("GET","index.php",true);
xmlhttp.send();
}
<4>パスワード検証の繰返しJsコード
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="<font color=red size=2px>*</font>";
if(password2.length==0)
{
document.getElementById("error4").innerHTML="<font color=red size=2px>* !</font>";
}
else
{
if(password2!=document.getElementById("password1").value)
{
document.getElementById("error4").innerHTML="<font color=red size=2px>* !</font>";
}
else
{
document.getElementById("error4").innerHTML="<font color=green size=2px>* !</font>";
}
}
}
}
xmlhttp.open("GET","index.php",true);
xmlhttp.send();
}
どうですか.簡単ですね.(未完待機)