标签:
<html>
<script>
function mysubmit(){
// var user_text=nform.nuser.value;
if((validate_flag==true)&&(user_flag==true)&&(pwd_flag==true)&&(checkuser==true)){
return true;
}else{
return false;
}
}
</script>
<head>
<script type="text/javascript" src="../../jquery/jquery-1.7.2.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
#wrapper{
margin:0 auto;
border:1px solid #333;
width:600px;
height:600px;
margin-top:200px;
}
.ctextinput{
width:150px;
border:1px solid #ccc;
}
.ctextinput:hover{
border-color:#75B9F0;
}
.cbtn{
width:50px;
height:30px;
background-color:transparent;
border:1px solid #BABFE0;
}
</style>
</head>
<body>
<div id="wrapper">
<form action="userreg.php" method="post" name="nform">
<table width="449" border="0" align="center">
<tr>
<td width="65">用户名:</td>
<td width="167"><input type="text" name="nuser" class="ctextinput" id="iuser"/></td>
<td width="203" class="yuser"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="npwd" class="ctextinput" id="ipwd"/></td>
<td class="ypwd"></td>
</tr>
<!--密码确认框-->
<tr>
<td>确认密码:</td>
<td><input type="password" name="npwd2" class="ctextinput" id="ipwd2"/></td>
<td class="ypwd2"></td>
</tr>
<tr>
<td><img title="点击刷新" src="./captcha.php" align="absbottom" onClick="this.src=‘captcha.php?‘+Math.random();"></img>
</td>
<td><input type="text" class="ctextinput" name="nyanzhengma" id="yanzhengma"/></td>
<td class="cyzm"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="登录" class="cbtn" name="nbtn" onClick="return mysubmit()"/></td>
<td></td>
</tr>
</table>
</form>
</div>
</body>
<script>
var validate_flag=false; //验证码开关
var user_flag=false; //用户名开关
var pwd_flag=false; //密码验证开关
var pwd_validate; //密码值开关
var checkuser=false; //用户名检测
$(document).ready(function(e) {
$("#yanzhengma").change(function(){
var validate=$("#yanzhengma").val();
$.ajax({
type:"POST",
data:{"yanzhengma":validate},
url:"deal/dealyzm.php",
success: function(data){
if(data){
validate_flag=true;
$(".cyzm").text("验证码正确");
}else{
validate_flag=false;
$(".cyzm").text("验证码错误");
}
},
error: function(edata){
alert(edata);
}
});
});
//用户名验证
$("#iuser").change(function(){
// var strReg=/\d+[a-zA-Z_]+|[a-zA-Z_]+\d+/;
// var strReg=/^[0-9]{3,20}$/;
//用户名不小于5位,不多于20位
var strReg=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._-]){4,16}$/;
var reg=new RegExp(strReg);
var uservalue=nform.nuser.value;
//if(reg.test(nform.nuser.value)){
// jubu_user_flag=true;
// }else{
// jubu_user_flag=false;
// }
// alert("fddf");
// var jubu_user_flag;
/* if(uservalue==""||(uservalue.length<5)||(uservalue.length>18)){
jubu_user_flag==false;
}else{
jubu_user_flag=true;
}*/
if(reg.exec(uservalue)){
// jubu_user_flag=true;
user_flag=true;
}else{
// jubu_user_flag=false;
user_flag=false;
}
if(user_flag==true){
$(".yuser").text("用户名格式正确");
}else{
$(".yuser").text("用户名不小于5位,以英文字母开头,允许数字和下划线");
}
//用户名检测是否重复
$.ajax({
type:"POST",
url:"deal/checkuser.php",
data:{"uservalue":uservalue},
success: function(data){
if(data){
$(".yuser").text("用户名已经存在");
checkuser=false;
}
//下面的逻辑代表用户名未存在
else{
checkuser=true;
}
},
error:function(edata){
}
});
});
$("#ipwd").change(function(){
pwd_validate=nform.npwd.value;
var strReg=/^[0-9a-zA-Z]{6,20}$/;
var reg=new RegExp(strReg);
if(reg.exec(pwd_validate)){
$(".ypwd").text("密码格式正确");
pwd_flag=true;
}else{
$(".ypwd").text("密码不小于6位");
pwd_flag=false;
}
});
$("#ipwd2").change(function(){
pwd2_validate=nform.npwd2.value;
if(pwd2_validate==pwd_validate){
$(".ypwd2").text("两次密码输入正确");
pwd_flag=true;
}else{
$(".ypwd2").text("两次密码输入错误");
pwd_flag=false;
}
});
});
</script>
</html>
deal目录的文件夹下,检测用户名是否重复,checkuser.php
<?php
header("Content-type: text/html; charset=utf-8");
include("../../conn/conn.php");
$user=$_POST[‘uservalue‘];
$sql="select *from ywtx_user where ywtx_name=‘$user‘";
$query=mysql_query($sql);
$rs=mysql_fetch_array($query);
if($rs==true){
echo true;
}else{
echo false;
}
?>
dealyzm.php,检测验证码是否正确
<?php
session_start();
$yanzhengma=$_POST[‘yanzhengma‘];
$syzm=$_SESSION["authnum_session"];
if($yanzhengma==$syzm){
echo true;
}
?>
好了,就这么多,自己原创的代码
标签:
原文地址:http://www.cnblogs.com/wgphp/p/4507783.html