簡訊提交驗證

来源:https://www.cnblogs.com/liubingyjui/archive/2018/12/10/10096173.html
-Advertisement-
Play Games

// 簡訊提交驗證 //$(function(){ var daoshu = 60; var timer = null; //手機號 function checkPhone(){ var phoneNumber = $.trim($('#t_code').val()); var phone = do ...


//-------------------------------------------簡訊提交驗證------------------------------------------//
$(function(){
var daoshu = 60;
var timer = null;
//手機號
function checkPhone(){
var phoneNumber = $.trim($('#t_code').val());
var phone = document.getElementById('t_code').value;
var smsCode = $.trim($('#smsCode').val());
if (phoneNumber == null || phoneNumber == "") {
//com.prompt('請輸入手機號!');
$('#yaerror').show();
$('#yaerror span').html('請輸入手機號');
return false;
//手機號正則
}else if(!(/^1[3456789]\d{9}$/.test(phone))) {
//com.prompt('手機號格式錯誤');
$('#yaerror').show();
$('#yaerror span').html('手機號格式錯誤');
return false;
}
return true;
}

//手機驗證碼
function checkSmsCode(){
var smsCode = $.trim($('#smsCode').val());
if (smsCode == null || smsCode == "") {
if(parent.location.href.indexOf('reg') >= 0){
// com.prompt('請輸入驗證碼');
$('#yaerror').show();
$('#yaerror span').html('請輸入驗證碼');
}else{
// com.prompt('請輸入驗證碼');
$('#yaerror').show();
$('#yaerror span').html('請輸入驗證碼');
}
return false;
}
return true;
}
//發送簡訊驗證碼
$(".send-sms").click(function(){
var mobile = $.trim($('#t_code').val());
//console.log(typeof mobile);

if(!mobile){
// com.prompt("請輸入手機號");
return false;
}
if(!checkPhone()){
return false;
}

send_login_code(mobile);
});
//獲取驗證碼倒計時1分鐘
function fn_daoshu(){
$(".daoshu").show();
daoshu -- ;
$(".daoshu").text(daoshu +'s');
if(daoshu == 0){
clear_Inter();
}
}
//清楚定時器
function clear_Inter(){
daoshu = 60;
$(".daoshu").text('60s').hide();
clearInterval(timer);
}
//發送簡訊驗證碼
function send_login_code(mobile)
{

$(".daoshu").show();
var code;
if($("#get_code").css("display") == 'none'){
code = 'is_empty';
}else {
if($('#yz_code').val() == ''){
com.prompt('請輸入圖形驗證碼');
return false;
}
code = $('#yz_code').val();
}
timer = setInterval(fn_daoshu,1000);
$("#smsCode").attr("disabled" , false);
$("#smsCode").attr("disabled" , false);
$.ajax({
type:"POST",
url:com.url.get_sms_code,
data:{
mobile: mobile,
},
datatype: "json",
success:function(res){
if(res.status == 'true'){
com.prompt("發送成功");
// $('#yaerror').show();
// $('#yaerror span').html('發送成功!');
}else{
com.prompt(res.info);
clear_Inter();
return false;
}
},
error: function(res){
//com.prompt('請重新獲取');
$('#yaerror').show();
$('#yaerror span').html('請重新獲取');
clear_Inter();
return false;
// console.log(res)
}
});
}

//用戶名
$("#t_usrname").focus(function(){
if($(this).val().length>0){
$('#userdelIco').show();
}

})
$("#t_usrname").blur(function(){
var username = $('#t_usrname').val();
if(username == '') return false;
//只能輸入中文 英文 和空格
var reg =/^[a-zA-Z\u4e00-\u9fa5\s ]{1,20}$/;
if(!(reg.test(username))) {
//com.prompt('姓名格式不正確');
$('#yaerror').show();
$('#yaerror span').html('姓名格式不正確');
return false;
}
// $('#userdelIco').hide();
return true;
});

//手機驗證碼
function t_usrname(){
var username = $('#t_usrname').val();
var reg =/^[a-zA-Z\u4e00-\u9fa5\s ]{1,20}$/;
if(username == null || username == "") {
return true;
}else if(username!=''){
if(!(reg.test(username))) {
//com.prompt('姓名格式不正確');
$('#yaerror').show();
$('#yaerror span').html('姓名格式不正確');
return false;
}
}
return true;
}
$('#t_usrname').on("input",function(){
var username = $.trim($('#t_usrname').val());
if(username.length>0){
$(this).parent('.posiv').siblings('.delico').show();
$(this).parent('.posiv').siblings('.delico').click;
}
})
//手機號焦點校驗
$('#t_code').on("focus",function(){
if($(this).val().length>0){
$('#teldelIco').show();
}
//已登錄狀態
if(parseInt(is_login)>'0' && parseInt(need_bind_mobie)>'1') {
$('#seleid').show(400);
$('#seleid').html(need_bind_mobie)
document.querySelector('#seleid').onclick=showMobile;
}else{

$('.flp.vufk').show();
}
})
function showMobile(){
$('#t_code').val(this.innerHTML)
$('#seleid').hide();
$('.flp.vufk').hide(400);
$('#yaerror').hide();
}
//已登錄
if(parseInt(is_login)>'0' && parseInt(need_bind_mobie)>'1'){
$('#tel_msg').click(function() {
var phone = $.trim($('#t_code').val());//手機號
var user_name = $.trim($("#t_usrname").val());//用戶名
var source = $.trim($("#source").val()); //暫時寫死
//換號了
if(phone!=need_bind_mobie){
console.log('換號了')
$('#yusuc').hide();
$('.flp.vufk').show(400);
$('#sendSms_Box').show();
noLogin();
}else{
$('.flp.vufk').hide(400);
console.log('沒換號')
//沒換號
var userInfo = {
user_name: user_name,
mobile: phone, //手機號
source:source,
pf_source:2,
ip: returnCitySN["cip"]

};
if(!t_usrname()){
return false;
}
if(!checkPhone()){
return false;
}

sendApiData({reg_source:userInfo.source,mobile:userInfo.mobile,name:userInfo.user_name,pf_source:2,ip: returnCitySN["cip"]});
}
})
}else{
console.log('沒登錄')
$('.flp.vufk').show();
$('#tel_msg').click(function(){
//沒登錄
noLogin();
})
}
//手機號失焦校驗
$('#t_code').blur(function(){
if(!checkPhone()){
return false;
}
})
//正在輸入檢驗
$('#t_code').on("input",function(){
var phoneNumber = $.trim($('#t_code').val());
if(parseInt(is_login)>'0' && parseInt(need_bind_mobie)>'1'){
if(phoneNumber!=need_bind_mobie){
$('#seleid').hide();
$('.flp.vufk').show(400);
}
if(phoneNumber==need_bind_mobie){
$('.flp.vufk').hide(400);
}
}else {
$('.flp.vufk').show();
}


if(phoneNumber.length>0){
$(this).parent('.posiv').siblings('.delico').show();
$(this).parent('.posiv').siblings('.delico').click;
}
var phone = document.getElementById('t_code').value;
var smsCode = $.trim($('#smsCode').val());
if (phoneNumber == null || phoneNumber == "") {
$(this).parent('.posiv').siblings('.delico').hide();
$(".send-sms").css({"background":"#eee","color":"#999"});
// $(".send-sms").attr('disabled','disabled');
return false;
//手機號正則
}else if(!(/^1[3456789]\d{9}$/.test(phone))) {
$(".send-sms").css({"background":"#eee","color":"#999"});
return false;
}
$(".send-sms").css({"background":"#ff5922","color":"#fff"});
$(".send-sms.dbing").css({"background":"#b41f5e","color":"#fff"});
$('#yaerror').hide();
$('#yaerror span').html('');
$('.flp.vufk').show();
})
$('#userdelIco').click(function(){
$(this).siblings('.posiv').find('.ptxt').val('');
// $('#t_usrname').val('');
clear_Inter();
$(this).hide();
$('.test_required').hide();
if($('#yaerror span').html()=='姓名格式不正確'){
$('#yaerror').hide();
if(!checkPhone()){
return false;
}
}
})

$('#teldelIco').click(function(){
$(this).siblings('.posiv').find('.ptxt').val('');
$(".send-sms").css({"background":"#eee","color":"#999"});
$("#smsCode").attr('disabled','disabled').val('');
clear_Inter();
$(this).hide();
$('.test_required').hide();
if($('#yaerror span').html()=='手機號格式錯誤'){
$('#yaerror').hide();
}
if($('#yaerror span').html()=='請輸入驗證碼'){
$('#yaerror').hide();
}
if($('#yaerror span').html()=='驗證碼錯誤'){
$('#yaerror').hide();
}
})

//沒登錄做驗證
function noLogin(){
var phone = $.trim($('#t_code').val());
var source = $.trim($("#source").val()); //暫時寫死
var yz_code = $.trim($('#smsCode').val());
var user_name =$.trim($("#t_usrname").val());
var userInfo = {
user_name:user_name,
mobile : phone, //手機號
code : yz_code , //驗證碼
source : source //來源渠道
};
if(!t_usrname()){
return false;
}
if(!checkPhone()){
return false;
}
if(!checkSmsCode()){
return false;
}
mobile_submit(userInfo);
}

//手機號登陸start
function mobile_submit(userInfo){
$.ajax({
type:"POST",
url: com.url.check_sms_code,
data:{
user_name:userInfo.user_name,
mobile : userInfo.mobile,
code : userInfo.code,
source : userInfo.source
},
dataType: 'json',
success: function(res){
if(res.status == 'true'){
// com.prompt('已提交');
$('#yaerror').show();
$('#yaerror span').html('已提交');
$('#t_code').val('');
$('#t_usrname').val('');
clear_Inter();
$("#smsCode").attr('disabled','disabled').val('');
$(".send-sms").css({"background":"#eee","color":"#999"});
$('.delico').hide();
$('#yaerror').hide();
$('#yaerror').html('');

sendApiData({reg_source:userInfo.source,mobile:userInfo.mobile,name:userInfo.user_name,pf_source:2,ip: returnCitySN["cip"]});

$('#yusuc').show();
$('#sendSms_Box').hide();
$('.module_10 .sendheight').css('height','14rem');
$('.pic_online10').css('height','17rem');
$('.ddt.last_getUser').css('height','11rem');
$('.No9,.last_getUser.fsd').css('height','12rem');
$('.index_apply .twrap06').css('height','12.3rem');

}else{
//com.prompt("驗證碼錯誤");
$('#yaerror').show();
$('#yaerror span').html('驗證碼錯誤');
}
},
error: function(res){
// com.prompt('請重新提交');
$('#yaerror').show();
$('#yaerror span').html('請重新提交!');
// console.log(res)
}
})
}

//手機號登陸start,最終提交代碼
function sendApiData(userInfo){
$.ajax({
type:"GET",
url: ucse_host+'/xuemao/formcollection/save_form_data.json',
data:userInfo,
xhrFields: {
withCredentials: true
},
dataType: 'json',
success: function(res){
if(res.result == 'succ'){
$('#yusuc').show();
$('#sendSms_Box').hide();
$('.module_10 .sendheight').css('height','14rem');
$('.pic_online10').css('height','17rem');
$('.ddt.last_getUser').css('height','11rem');
$('.No9,.last_getUser.fsd').css('height','12rem');
$('.index_apply .twrap06').css('height','12.3rem');

}else{
//com.prompt("驗證碼錯誤");
$('#yaerror').show();
$('.vufk .error').show();
}
},
error: function(res){
//com.prompt('請重新提交');
$('#yaerror').show();
$('#yaerror span').html('請重新提交');

// console.log(res)
}
})
}
//點擊其他位置隱藏
$('body').click(function(e) {
var target = $(e.target);
if(!target.is('#t_code') && !target.is('#seleid')) {
$('#seleid').hide();
}
});

$('body').click(function(e) {
var target = $(e.target);
if(!target.is('#t_usrname')) {
$('#userdelIco').hide();
}
});
$('body').click(function(e) {
var target = $(e.target);
if(!target.is('#t_code')) {
$('#teldelIco').hide();
}
});
})

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 在開發中,通常會保持兩個分支master分支和develop分支,但是如果因為develop上面迭代太多而沒有及時維護master,最後想丟棄master而直接將測試確認過的develop強推到master,該怎麼操作呢? 網上搜了一下,但是真正自己使用起來卻又暴露出各種問題。因此,做如下總結分享, ...
  • ` ` ...
  • js 介面: 調用: 具體詳見官方api,很詳細 http://element.eleme.io/#/zh-CN/component/upload#attribute ...
  • Blob, Uint8Aray, atob/btoa in lt IE9 browser ...
  • 效果展示 項目背景: 由於瀏覽器的限制,web批量下載體驗不好以及無法下載文件夾。採用Electron技術,通過js開發PC應用程式,著力解決批量下載、斷點續傳、文件夾下載等問題。配合網頁版網盤使用,單個小文件使用瀏覽器內置下載,單個大文件、多文件、文件夾調用PC應用程式,提升下載體驗。 技術棧 E ...
  • 首先在最外層div添加v-if="isReloadAlive",並創建變數isReloadAlive = true 隨後添加provide()以及reload方法,如下: export default { provide() { return { reload: this.reload } }, d ...
  • ...
  • vue route transition vue router 切換動畫 特性 模擬前進後退動畫 基於css3流暢動畫 基於sessionStorage,頁面刷新不影響路由記錄 路由懶載入,返回可記錄滾動條位置 前進後退的判斷與路由路徑規則無關 支持任意基於Vue的UI框架 demo 手機掃碼 "在 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...