// 手机号码验证
jQuery.validator.addMethod("isMobile", function(value, element) {
var length = value.length;
var mobile = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
return this.optional(element) || (length == 11 && mobile.test(value));
}, "请输入正确的手机号码");
jQuery.validator.addMethod("isMobile2", function(value, element) {
status1=checkphone(value);
return this.optional(element) || status1;
}, "此手机号码已经注册");
jQuery.validator.addMethod("isUsername", function(value, element) {
status2=checkname(value);
return this.optional(element) || status2;
}, "此账号已经被注册");
jQuery.validator.addMethod("ischecked", function(value, element) {
status2=ischecked(value);
return this.optional(element) || status2;
}, "此账号已经被注册");
//验证输入的验证码是否正确
jQuery.validator.addMethod("yzcheck",function(value,element){
status3=checkCode(value);
return this.optional(element) || status3 ;
},"验证码错误");
$().ready(function() {
$("#firstform1").validate({
debug: true, //调试模式取消submit的默认提交功能
//errorClass: "label.error", //默认为错误的样式类为:error
focusInvalid: false, //当为false时,验证无效时,没有焦点响应
onkeyup: false,
submitHandler: function(form){ //表单提交句柄,为一回调函数,带一个参数:form
register_1();
return false;
//form.submit(); //提交表单
},
/*errorLabelContainer: "#messageBox", //显示错误信息的容器ID
wrapper: "li", //包含每个错误信息的容器*/
rules:{
Username:{
required: true,
minlength:6,
maxlength:18,
isUsername:true
},
phone:{
required:true,
isMobile:true ,
isMobile2:true
},
agreen:{
// ischecked:true,
required:true
},
yzmm:{
required:true,
yzcheck:true,
},
password:{
required:true,
minlength:6,
maxlength:18,
},
repassword:{
required:true,
equalTo:"#password"
}
},
messages:{
Username:{
required: "请填写姓名",
minlength: "字符长度不能小于6个字符",
maxlength: "字符长度不能大于18个字符" ,
isUsername:"此账号已经被注册"
},
phone:{
required: "请输入您的联系电话",
isMobile: "请输入一个有效的联系电话" ,
isMobile2:"此手机号码已经被注册!"
},
agreen:{
required:"微融服务器协议必须",
},
yzmm:{
required:"验证码必须",
yzcheck:"验证码错误",
},
password:{
required:"密码必须",
minlength:"密码长度至少为6位",
maxlength:"密码长度不能超过18位"
},
repassword:{
required:"确认密码必须",
equalTo:"确认密码不正确"
}
} ,
errorPlacement: function(error, element) {
if ( element.is(":radio") )
error.appendTo ( element.parent() );
else if ( element.is(":checkbox") )
error.appendTo ( element.parent() );
else if ( element.is("input[name=captcha]") )
error.appendTo ( element.parent() );
else
error.insertAfter(element);
}
});
});
function checkphone(objvalue){
$.ajax({
url:"action/RegAction.php?action=checkp",
async:false,//异步请求
cache:false,//不缓存
type:"post",
data:{"phone":objvalue},
dataType:"json",
beforeSend:function(){
//$(".layer").fadeOut(500);
},
error:function(){
alert('网络原因');
},
success:function(data){
if(data>=1){
result=false;
}
else{
result=true;
}
}
});
return result;
}
//检测用户名是否存在
function checkname(objvalue){
$.ajax({
url:"action/RegAction.php?action=recheck",
async:false,//异步请求
cache:false,//不缓存
type:"post",
data:{"Username":objvalue},
dataType:"json",
beforeSend:function(){
//$(".layer").fadeOut(500);
},
error:function(){
alert('网络原因');
},
success:function(data){
if(data>=1){
result=false;
}
else{
result=true;
}
}
});
return result;
}
//获取短信
function ischecked(obj){
}
function sendNote1(){
if (status1&status2){
var phone=escape($("input[name='phone']").val());
$.ajax({
url:"action/RegAction.php?action=getMobileCode",
async:true,//设为false会等待ajax执行完毕在执行后面的JS代码
type:"post",
data:{"phone":phone},
dataType:"json",
error:function(){
alert("网络 Error,请稍后尝试注册");
},
success:function(data){
if(data == 1){
seconds=60;
showRzz(seconds,speed,phone);
// $("#getSms").html("<font color=red>验证码已发送, 请耐心等待</font>");
//$("#zhuceButton").prop('disabled', false);
//hideTopError()
}else{
$("#yzmm").removeClass("has-success").addClass("has-error");
$("input[name='yzmm']").val('');
$("input[name='yzmm']").attr("placeholder","验证码不正确");
result=false;
}
}
});// end ajax call
}
}
var seconds = 30;
var speed = 1000;
function showRzz(seconds,speed,phone){
var rzz=$("#getSms1");
var oldText=$("#getSms1").html();
var txt = "<a class='center-block' href='javascript:void(0)'>("+seconds +"发送验证码)</a>";
var timeIdd = setTimeout("showRzz(seconds--,speed)",speed);
if(seconds == 0){
txt="<a href=\"#.\" onClick=\"sendNote1()\" class=\"center-block color58\">获取验证码<span class=\"color4045\">60</span></a>";
clearTimeout(timeIdd);
// alert(seconds)
};
rzz.html(txt);
}
function checkCode(objvalue){
$.ajax({
url:"action/RegAction.php?action=reCode",
async:false,//异步请求
cache:false,//不缓存
type:"post",
data:{"yzmm":objvalue},
dataType:"json",
beforeSend:function(){
//$(".layer").fadeOut(500);
},
error:function(){
alert('网络原因');
},
success:function(data){
if(data==1){
result=true;
}
else{
result=false;
}
}
});
return result;
}
function register_1(){
var username=$("input[name=Username]").val(); //用户名
var phone=$("input[name=phone]").val();//手机号码
$.ajax({
url:"action/ManagerAction.php?action=register_1",
async:false,//异步请求
cache:false,//不缓存
type:"post",
data:{"phone":phone,"username":username},
dataType:"json",
beforeSend:function(){
//$(".layer").fadeOut(500);
},
error:function(){
alert('网络原因');
},
success:function(data){
if(data==1){
window.location.href="register_s1.php?action=step2";
// result=true;
}
else{
alert("网络原因,注册失败!")
result=false;
}
}
});
}
转载于:https://www.cnblogs.com/zoupufa/p/4226981.html