Dowemo

The form validates a piece of js, primarily a regular validation of a password


/**


 * Created by Administrator on 2015/9/30.


 */


//根据屏幕设置根值


var mrT = 0;


var messageCode = "";


var interval = null;


(function (doc, win) {


 var docEl = doc.documentElement,


 resizeEvt = 'orientationchange' in window? 'orientationchange' : 'resize',


 recalc = function () {


 var clientWidth = docEl.clientWidth;


 if (!clientWidth) return;


 docEl.style.fontSize = 20 * (clientWidth/320) + 'px';


 };


 if (!doc.addEventListener) return;


 win.addEventListener(resizeEvt, recalc, false);


 doc.addEventListener('DOMContentLoaded', recalc, false);


})(document, window);



(function(){


 var desH = 925;


 var desW = 640;


 var wrapper = $('#wrapper');


 var viewHeight = $('body, html').height();


 var viewWidth = $(window).width();


 //等比初始化高度背景


 function init(){


 wrapper.css({


 width: viewWidth,


 height: (viewWidth*desH)/desW


 });


 }


 //init();


})();


(function(){


 var oWrap = $('#registered');


 var oUser=oWrap.find('[name=user]');


 var oPhone = oWrap.find('[name=phone]');


 var oCode = oWrap.find('[name=code]');


 var oPass = oWrap.find('[name=pass]');


 var oPassyes = oWrap.find('[name=passyes]');


 var submitBtn = oWrap.find('[class=s_btn]');


 var getcode = $('#getcode');


 var regMobileNo = '';



 var isYst = true;


 var Through = true;


 /*var AERRORSTRING = {


 MOBILE_ERR : '您输入的手机号码有误',


 PASSWORD_ERR : '8-20位字符,包含数字、字母或特殊符号',


 CODE_ERR : '验证码不正确',


 PASSWORDYES_ERR : '两次密码不一致'


 };*/


 var AeleCheckObj = ['pass', 'passyes','phone','code'];


 var checkMobile = function (mobile, fn) {


 if (!mobile ||!mobile.length) {


 fn(false, 'MOBILE_ERR');


 return;


 }


 if (!('' + mobile).match(/^[1][3|5|7|8][0-9]{9}$/)) {


 fn(false, 'MOBILE_ERR');


 return;


 }


 fn(true, null);


 }



 var checkCode = function(code, fn){


 if(!code || code.length<6){


 fn(false, 'CODE_ERR');


 return;


 }


 if(code!= messageCode){


 fn(false, 'CODE_ERR');


 return;


 }


 fn(true, null);


 };



 var checkUser = function (user, fn) {


//var reg =


///^(?!(([1][3|5|7|8][0-9]{9})|([w-]+(.[w-]+)*@[w-]+(.[w-]+)+)))([0-9a-zA-Z_u4E00-u9FBF]+)/;



 if (!user ||!user.length) {


 fn(false, 'LOGINNAME_NULL');


 return;


 }



 if(!user.match(/^[a-zA-Z]w{3,19}$/)){


 //debugger;


 fn(false, 'LOGINNAME_SIZE');


 return;


 }



 if (user.length <4 || user.length> 20) {


 fn(false, 'LOGINNAME_SIZE');


 return;


 }



 fn(true, null);


 }



 var checkPassword = function (password, fn) {


 var iNow = 0;


 if (password.match(/s/)) {


 fn(false, 'PASSWORD_ERR');


 return;


 }


 if (!password ||!password.length) {


 fn(false, 'PASSWORD_ERR');


 return;


 }


 if (password.match(/[u4E00-u9FA5]/g)) {


 fn(false, 'PASSWORD_ERR');


 return;


 }


 if(password.match(/[0-9]/g)){


 iNow++;


 }


 if(password.match(/[a-z]/ig)){


 iNow++;


 }


 if(password.match(/(.[^a-z0-9])/ig)){


 iNow++;


 }


 if(password.match(/[~!@#$%^&*]/g)){


 iNow++;


 }


 if (password.length <8 || password.length> 20) {


 fn(false, 'PASSWORD_ERR');


 return;


 }


 if(iNow <2){


 fn(false, 'PASSWORD_ERR');


 return;


 }


 fn(true, null);


 };



 var checkPasswordYes = function(pass, passyes, fn){


 var iNow = 0;


 if (passyes.match(/s/)) {


 fn(false, 'PASSWORD_ERR');


 return;


 }


 if (!passyes ||!passyes.length) {


 fn(false, 'PASSWORD_ERR');


 return;


 }


 if (passyes.match(/[u4E00-u9FA5]/g)) {


 fn(false, 'PASSWORD_ERR');


 return;


 }


 if(passyes.match(/[0-9]/g)){


 iNow++;


 }


 if(passyes.match(/[a-z]/ig)){


 iNow++;


 }


 if(passyes.match(/(.[^a-z0-9])/ig)){


 iNow++;


 }


 if(passyes.length && $(this).iNow){


 iNow--;


 }


 if (passyes.length <8 || passyes.length> 20) {


 fn(false, 'PASSWORD_ERR');


 return;


 }


 if(iNow <2){


 fn(false, 'PASSWORD_ERR');


 return;


 }



 if(!passyes.length ||!pass.length){


 fn(false, 'PASSWORDYES_ERR');


 return;


 }


 if(passyes!= pass){


 fn(false, 'PASSWORDYES_ERR');


 return;


 }


 fn(true, null);


 };


 function throughFn(flag, ele, checkStr){


 if (!flag) {



 ele.next().attr("class","icon err");


 Through = false;


 } else {


 ele.next().attr("class","icon ok");


 Through = true;


 }


 }



 //点击获得验证码


 getcode.on('click', function(){


 var ele = $("input[name='phone']");


 var phone = ele.val();


 eval(ele.attr("data-fn"))(ele.val(), function(flag, err){


 throughFn(flag, ele, err);


 });


 if(!phone ||!phone.length ||!('' + phone).match(/^[1][3|5|7|8][0-9]{9}$/)){


 return ;


 }


 $.ajax({


 type: "POST",


 url: "/nci_map/InviteRegist",


 xhrFields:{


 withCredentials:false


 },


 crossDomain:true,


 data: {"phone":phone,"type":"search"}, 


 success: function(res){


 messageCode=res;


 var resObj = eval("("+res+")");


 if(resObj.head.rspCode==200){


 if (!getcode.hasClass('disabled')) {


 getCaptcha(getcode,true);


 $.ajax({


 type: "POST",


 url: "/nci_map/InviteRegist",


 xhrFields:{


 withCredentials:false


 },


 crossDomain:true,


 data: {"phone":phone,"type":"getVerify"}, 


 success: function(res){


 messageCode=res;


 var resObj = eval("("+res+")");


 if(resObj.head.rspCode==200){


 messageCode=resObj.body.verifyCode;


 regMobileNo = phone;


 }else{


 getcode.removeClass('disabled');


 getcode.html('获取验证码');


 clearInterval(interval);


 alert(resObj.head.rspMsg);


 }


 }, 


 });


 }


 }else{


 getcode.removeClass('disabled');


 getcode.html('获取验证码');


 clearInterval(interval);


 alert(resObj.head.rspMsg);


 }


 },


 });


 });



 $(document).on('input', function(ev){


 var targetEl = ev.target || ev.srcElement;


 var ele = oWrap.find('[name='+targetEl.name+']');



 if(targetEl.dataset.fn == 'checkPasswordYes'){


 eval(targetEl.dataset.fn)(ele.val(), oPass.val(), function(flag, err){


 throughFn(flag, ele, err);


 });


 }else{


 eval(targetEl.dataset.fn)(ele.val(), function(flag, err){


 throughFn(flag, ele, err);


 });


 }



 });


 submitBtn.on('touchstart', function(){


 if(!$('[name=agree]').prop('checked')){


 alert('必须同意世纪金融用户使用协议,才能完成注册')


 return;


 }



 if(isYst){


 $.each(AeleCheckObj, function(i, ele){


 var ele = $('[name='+ele+']');


 if(!ele.val().length){



 ele.next().attr("class","icon err");


 Through = false;


 }else{


 if(ele.data('fn') == 'checkPasswordYes'){


 eval(ele.data('fn'))(ele.val(), oPass.val(), function(flag, err){


 throughFn(flag, ele, err);


 });


 }else{


 eval(ele.data('fn'))(ele.val(), function(flag, err){


 throughFn(flag, ele, err);


 });


 }


 }


 });


 }



 if($('.err').length>0){


 alert('请确定注册信息是否填写正确');


 Through = false;


 }


 if(Through){ //可提交


 if(regMobileNo!= $("input[name='phone']").val()){


 alert("当前填写手机号与待注册手机号不一致!");


 return;


 }


 //可提交


 if($("input[name='code']").val()!=messageCode){


 alert("验证码不正确!");


 return;


 }


 var formParam = $("#registered").serialize()+"&type=regist"+"&invite="+getUrlParam();//序列化表格内容为字符串


 formParam += '&user=sj'+$("input[name='phone']").val();


 $.ajax({


 type: "post",


 url: "/nci_map/InviteRegist", 


 data: formParam,


 xhrFields:{


 withCredentials:false


 },


 crossDomain:true,


 success: function(res){


 var json = $.parseJSON(res);


 if(json.head.rspCode === "200"){


 window.location.href = "./success.html?ios="+json.body.iosAddress+"&android="+json.body.androidAddress+"&imgUrl="+json.body.imgAddress;


 }else{


 alert(json.head.rspMsg);


 }


 }, 


 error : function() {


 alert("异常!"); 


 } 


 });


 }


 isYst =!isYst;


 });


})();


//遮罩层



(function(){


 var protocol = $('#protocol-us');


 var protocolTips = $('.protocol-tips');


 var masklayer = $('.masklayer');


 var content = protocolTips.find('div');


 var titC = protocolTips.find('h2');


 var imgBtn = titC.find('img');


 content.css({


 height: protocolTips.height() - titC.height() - ((20 * (document.documentElement.clientWidth/320))*2) +"px",


 margin: '.5rem 0'


 });


 protocol.on('touchstart click', function(){


 //$('body, html').css({height: $(window).height()});+$(window).scrollTop()


 protocolTips.css({


 top: ($(window).height()-protocolTips.height())/2+"px"


 });


 masklayer.css({


 height: $(window).height()+$(window).scrollTop()+"px"


 });


 protocolTips.fadeIn();


 masklayer.fadeIn();


 $('body').css({


 "overflow":"hidden",


 height: $(window).height()


 });


 //$('body, html').on('touchmove.doc', function(ev){return false;});


 return false;


 });


 imgBtn.on('touchstart click', function(){


 $('body, html').off('.doc');


 protocolTips.fadeOut();


 masklayer.fadeOut();


 $('body').css({


 "overflow":"",


 height: 'auto'


 });


 });


 masklayer.on('touchstart click', function(){


 //$(document).off('.doc');


 protocolTips.fadeOut();


 masklayer.fadeOut();


 $('body').css({


 "overflow":"",


 height: 'auto'


 });


 });


})();



function getCaptcha(obj) {


 obj.addClass('disabled');


 var previousText = '获取验证码';


 var msg = '$秒后重新发送';



 var left = 120;


 interval = setInterval((function () {


 if (left> 0) {


 obj.html(msg.replace('$', left--));


 } else {


 obj.html(previousText);


 obj.removeClass('disabled');


 clearInterval(interval);


 }


 }), 1000); 


}



/**


 * 获取邀请人 


 *//*


function getYQR(){


 var para = window.location.search.substr(1).replace("+","#");


 if(para.indexOf("from")==0 || para.indexOf("isappinstalled")==0){


 return"";


 }else{


 return para.split('&')[0];


 }


}*/


/**


* 获取请求参数


*/


function getUrlParam() {


 var para = window.location.search.substr(1).replace("+","#");


 if(para.indexOf("from")==0 || para.indexOf("isappinstalled")==0){


 return "&"+para;


 }else{


 return para;


 }


}












Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs