//user input valid basic js function selectall_(){ if( $("input[name='selectall']").attr("checked")=="checked" ) { $(":checkbox").removeProp("checked");//jquery1.9鐗堝吋瀹笷F璁剧疆 $(":checkbox").removeAttr("checked"); } else { $(":checkbox").prop("checked", "checked"); $(":checkbox").attr("checked", "checked"); } } //鍘绘帀绌烘牸 function trim(str){ if (typeof(str) == "string"){ return str.replace(/^\s*|\s*$/g, ""); } else{ return str; } } //鏄惁涓虹┖ function isEmpty(val){ switch (typeof(val)) { case 'string': return trim(val).length == 0 ? true : false; break; case 'number': return val == 0; break; case 'object': return val == null; break; case 'array': return val.length == 0; break; default: return true; } } //鍑芥暟锛欵-Mail妫€娴 function isMail(str){ var Re = /^\s*([A-Za-z0-9_-]+(\.\w+)*@(\w+\.)+\w{2,3})\s*$/; if( Re.test(str) ){ return true; }else{ return false; } } //鍑芥暟锛氱數璇濇娴 function isTel(str){ var Re=/^\s*[.0-9]{8,11}\s*$/; if(!Re.test(str) || str<30000000 || str>20000000000){ return false; }else{ return true; } } //鍑芥暟锛氭墜鏈哄彿妫€娴 function is_mobile(str){ var Re = /^1[0-9]{10}$/; if( Re.test(str) ){ return true; }else{ return false; } } //鍑芥暟锛氫綇瀹呯數璇濇娴 function isPhone_(str){ var Re = /^0[0-9]{2,3}\-[0-9]{7,8}$/; if( Re.test(str) ){ return true; }else{ return false; } } //鍑芥暟锛歈Q鍙风爜妫€娴 function isQQ(str){ var Re = /^\s*[.0-9]{5,10}\s*$/; if( Re.test(str) ){ return true; }else{ return false; } } //鍑芥暟锛氶偖缂栨娴 function isPC(str){ var Re = /^[0-9]{6}$/; if( Re.test(str) ){ return true; }else{ return false; } } //鍑芥暟锛氭暟瀛楁娴 function isNum(str){ var Re = /^[0-9]+$/; if( Re.test(str) ){ return true; }else{ return false; } } //鍑芥暟锛氭鏌ユ槸鍚︿负 YYYY-MM-DD || YYYY/MM/DD 鐨勬棩鏈熸牸寮 function isdate(str){ var Re = /^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2})$/; if( Re.test(str) ){ return true; }else{ return false; } } //鍑芥暟锛氬尮閰嶈韩浠借瘉(15浣嶆垨18浣? function isidcard(str) { var Re = /\d{15}|\d{18}/; if( Re.test(str) ){ return true; }else{ return false; } } //鍑芥暟锛氬繀濉啓椤瑰強闀垮害 function isReqired(str, minl, maxl){ var Re = eval("/^\\S{"+ minl +","+ maxl +"}$/"); if( Re.test(str) ){ return true; }else{ return false; } } //鍒ゆ柇鑻辨枃瀛楃涓 function chkstr(str) { for (var i = 0; i < str.length; i++) { if (str.charCodeAt(i) < 127 && !str.substr(i,1).match(/^\w+$/ig)) { return false; } } return true; } //鍑芥暟锛氬崟閫夋鏄惁閫変腑涓€涓 function radioChecked(form, radioName) { var eles = document.forms[form].elements; for (var i = 0; i < eles.length; i++) { if (eles[i].name == radioName && eles[i].checked) { return true; } } return false; } //寮圭獥,鑷姩鍏抽棴 function msgalert(content){ $('#myModal .modal-body').html(content); $('#myModal').modal('show'); setTimeout(function(){ $('#myModal').modal('hide'); },2000); } //鍒犻櫎锛屽脊绐楁彁绀 function confirmdel(url, str) { var gourl = false; if( str=='' ) gourl = true; else gourl = confirm(str); if( gourl ) { $.get(url,'',function(data){ if( data.message!='' ) { var content = data.error==0 ? data.message : ''+data.message+''; $('#myModal .modal-body').html(content); $('#myModal').modal('show'); setTimeout(function(){ $('#myModal').modal('hide'); if( data.error==0 ) { if( data.gourl=='' ) $('#listtable').html(data.content); else window.location.href=data.gourl; } },2000); } else { if( data.gourl=='' ) $('#listtable').html(data.content); else window.location.href=data.gourl; } }); } } //琛ㄥ崟鎻愪氦 ajax $(function(){ $('.ajaxform').each(function(){ $(this).ajaxForm({ //$(this).ajaxSubmit({ beforeSubmit: checkForm, // pre-submit callback success: complete, // post-submit callback dataType: 'json' }); function complete(data){ //alert(data); if( data.message!='' ) { var content = data.error==0 ? data.message : ''+data.message+''; $('#myModal .modal-body').html(content); $('#myModal').modal('show'); setTimeout(function(){ $('#myModal').modal('hide'); if( data.error==0 ) { if( data.gourl=='' ) $('#listtable').html(data.content); else window.location.href=data.gourl; } },2000); } else { if( data.gourl=='' ) $('#listtable').html(data.content); else window.location.href=data.gourl; } if( data.after_function!='' ) { var f = data.after_function; window[f](); } $('.submit').attr("disabled", false); } }); }); //寮圭獥,鎵嬪姩鍏抽棴 function showbox(url, title){ $.get(url,'',function(data){ if( data.message!='' ) { var content = data.error==0 ? data.message : ''+data.message+''; $('#myModal .modal-body').html(content); $('#myModal').modal('show'); setTimeout(function(){ $('#myModal').modal('hide'); if( data.error==0 ) { if( data.gourl=='' ) $('#listtable').html(data.content); else window.location.href=data.gourl; } },2000); } else { $('#myModal .modal-title').html(title); $('#myModal .modal-body').html(data.content); $('#myModal').modal('show'); } }); } //閫夋嫨鍦板尯 function sel_region(obj, level, str){ var id = $(obj).val(); $.post('/region/selregion.html',{"id":id,"level":level},function(data){ if( data.content!='' ){ $('#'+str).html(data.content); $('#'+str).show(); if( level==2 ){ $(obj).parent().find('select[name=district]').hide(); } } }); } //浼氬憳娉ㄥ唽楠岃瘉鐢ㄦ埛鍚 function is_registered( str, type ) { var submit_disabled = false; var unlen = str.replace(/[^\x00-\xff]/g, "**").length; if ( !chkstr( str ) ) { $('#username_notice').html('鐢ㄦ埛鍚嶈濉啓鏁板瓧鎴栧瓧姣岦/span>'); $('#username_notice').show(); $('#btn-register').attr('disabled', true); // setTimeout(function(){ // $('#username_notice').fadeOut(); // },2000); return false; } if ( unlen < 4 || unlen > 16 ) { $('#username_notice').html('鐢ㄦ埛鍚嶉暱搴﹀繀椤讳负4-16浣嶅瓧绗?/span>'); $('#username_notice').show(); $('#btn-register').attr('disabled', true); // setTimeout(function(){ // $('#username_notice').fadeOut(); // },2000); return false; } $.post('/member/is_registered.html',{"username":str, "type":type},function(data){ if( data.error==1 ){ $('#username_notice').html(''+data.message+''); $('#username_notice').show(); $('#btn-register').attr('disabled', true); // setTimeout(function(){ // $('#username_notice').fadeOut(); // },2000); } else{ $('#username_notice').html(''); $('#username_notice').show(); } }); } //浼氬憳娉ㄥ唽楠岃瘉鎵嬫満 function mobile_registered( str) { var submit_disabled = false; if ( !is_mobile( str ) ) { $('#mobile_notice').html('鏃犳晥鐨勬墜鏈哄彿'); $('#mobile_notice').show(); $('#btn-register').attr('disabled', true); return false; } $.post('/member/is_registered.html',{"username":str, "type":'mobile'},function(data){ if( data.error==1 ){ $('#mobile_notice').html(''+data.message+''); $('#mobile_notice').show(); $('#btn-register').attr('disabled', true); } else{ $('#mobile_notice').html(''); $('#mobile_notice').show(); } }); } function check_password( password ) { if ( password.length < 6 ) { $('#password_notice').html('瀵嗙爜闀垮害涓嶈兘灏忎簬6涓瓧绗?/span>'); $('#password_notice').show(); $('#btn-register').attr('disabled', true); return false; } if ( password.length >20 ) { $('#password_notice').html('瀵嗙爜闀垮害涓嶈兘澶т簬20涓瓧绗?/span>'); $('#password_notice').show(); $('#btn-register').attr('disabled', true); return false; } else { $('#password_notice').html(''); $('#password_notice').show(); $('#btn-register').attr('disabled', false); } } function check_conform_password( conform_password ) { if ( conform_password != $('#password').val() || conform_password=='' ) { $('#re_password_notice').html('涓ゆ杈撳叆鐨勫瘑鐮佷笉涓€鑷滁/span>'); $('#re_password_notice').show(); $('#btn-register').attr('disabled', true); return false; } else { $('#re_password_notice').html(''); $('#re_password_notice').show(); } } //update 2018.12.14 浼氬憳娉ㄥ唽楠岃瘉鐮侀獙璇 function check_captcha(str){ var submit_disabled = false; if ( str.length!=4 ){ $('#captcha_notice').html('璇疯緭鍏ラ獙璇佺爜'); $('#captcha_notice').show(); $('#btn-register').attr('disabled', true); return false; } $.post('/member/chk_captcha.html',{"captcha":str},function(data){ if( data.error==1 ){ $('#captcha_notice').html(''+data.message+''); $('#captcha_notice').show(); $('#btn-register').attr('disabled', true); } else{ $('#captcha_notice').html(''); $('#captcha_notice').show(); } }); } //鑾峰彇鐭俊楠岃瘉鐮 function get_sms_code(t){ if( t=='check' ){ var m = $('#mobile'); var f = $('.form-message'); var c = $('.code_ps'); var mobile = m.val(); } var b = f.find('.btn-sendcode'); if( !is_mobile(mobile) ){ f.find('.mobile_ps').html('鏃犳晥鐨勬墜鏈哄彿鐮?); f.find('.mobile_ps').show(); return false; } //m.attr('readonly', true);//閿佸畾濉啓鐨勬墜鏈哄彿 if( t=='check' ){ $('#btn-get-smscode').attr('disabled', true); $('#btn-get-smscode').text("鐭俊鍙戦€佷腑"); } $.post('/Member/get_sms_code.html',{"mobile":mobile,"type":t},function(data){ if( data.error==1 ){ f.find('.code_ps').html(data.message); f.find('.code_ps').show(); //m.attr('readonly', false); b.attr('disabled', false); } else{ f.find('.code_ps').html('鐭俊鍙戦€佹垚鍔?); f.find('.code_ps').show(); b.attr('disabled', true); b.val(curCount + "绉?); InterValObj = window.setInterval(SetRemainTime, 1000); //鍚姩璁℃椂鍣紝1绉掓墽琛屼竴娆 } }); } var InterValObj; //timer鍙橀噺锛屾帶鍒舵椂闂 var curCount = 60;//褰撳墠鍓╀綑绉掓暟 //timer澶勭悊鍑芥暟 function SetRemainTime() { if (curCount == 0) { window.clearInterval(InterValObj);//鍋滄璁℃椂鍣 $('#btn-get-smscode').attr('disabled', false);//鍚敤鎸夐挳 $('#btn-get-smscode').val("鑾峰彇楠岃瘉鐮?); $('#btn-get-smscode').text("鑾峰彇楠岃瘉鐮?); curCount = 60; } else { curCount--; $('#btn-get-smscode').val(curCount + "绉掑悗閲嶆柊鍙戦€?); $('#btn-get-smscode').text(curCount + "绉掑悗閲嶆柊鍙戦€?); } } function register() { var username = $('#user_name').val(); var password = $('#password').val(); var confirm_password = $('#re_password').val(); // 妫€鏌ヨ緭鍏 $('#btn-register').attr('disabled', true); if (username.length == 0) { $('#username_notice').html('鐢ㄦ埛鍚嶄笉鑳戒负绌裹/span>'); $('#username_notice').show(); return false; } else if (username.match(/^\s*$|^c:\\con\\con$|[%,\'\*\"\s\t\<\>\&\\]/)) { $('#username_notice').html('鏃犳晥鐨勭敤鎴峰悕'); $('#username_notice').show(); return false; } else if (username.length < 4 || username.length >16) { $('#username_notice').html('鐢ㄦ埛鍚嶉暱搴﹀繀椤讳负4-16浣嶅瓧绗?/span>'); $('#username_notice').show(); return false; } if( $('#email').length>0 ){ var email = $('#email').val(); if (email.length > 0) { if ( ! (Utils.isEmail(email))) { $('#email_notice').html('鏃犳晥鐨勯偖绠卞湴鍧€'); $('#email_notice').show(); return false; } } } if (password.length < 6 || password.length >20){ $('#password_notice').html('瀵嗙爜蹇呴』涓?-20浣嶅瓧绗?/span>'); $('#password_notice').show(); return false; } if (confirm_password != password ){ $('#re_password_notice').html('涓ゆ杈撳叆瀵嗙爜涓嶄竴鑷滁/span>'); $('#re_password_notice').show(); return false; } if( $('#mobile').length>0 ){ var sms_code = $('#sms_code').val(); var mobile = $('#mobile').val(); if ( !is_mobile(mobile) ){ $('#mobile_notice').html('鏃犳晥鐨勬墜鏈哄彿'); $('#mobile_notice').show(); return false; } if (sms_code.length != 6){ $('#code_notice').html('鏃犳晥鐨勬墜鏈洪獙璇佺爜'); $('#code_notice').show(); return false; } } //update 2018.12.14 if( captcha_open=='1' && captcha_type=='0' ){ captcha = $('#captcha').val(); if( captcha=='' ){ $('#captcha_notice').html('璇峰~鍐欓獙璇佺爜'); $('#captcha_notice').show(); return false; } } if( captcha_open=='1' && captcha_type=='1' && capcha_valid == 0 ){ $('#register_notice').html('璇峰厛瀹屾垚璇佺爜'); $('#register_notice').show(); return false; } //// return true; } //楠岃瘉鏀惰揣浜轰俊鎭 function checkconsignee(){ if( $('#consignee').val()=='' ){ msgalert('璇峰~鍐欐偍鐨勫鍚?); } if( $('#phone').val()=='' ){ msgalert('璇峰~鍐欐偍鐨勬墜鏈哄彿'); } if( !is_mobile( $('#phone').val() ) ){ msgalert('鎵嬫満鍙锋牸寮忎笉姝g‘'); } if( $('#address').val()=='' ){ msgalert('璇峰~鍐欐偍鐨勮缁嗗湴鍧€'); } else{ return true; } return false; }