程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> 條件判斷-Js判斷條件激活按鈕。

條件判斷-Js判斷條件激活按鈕。

編輯:編程綜合問答
Js判斷條件激活按鈕。

驗證正確的手機格式和統計數量大於0,激活按鈕。否則按鈕為灰。用Js實現。請各位大牛幫忙。

最佳回答:


var isChinaMobile = /^134[0-8]d{7}$|^(?:13[5-9]|147|15[0-27-9]|178|18[2-478])d{8}$/; //移動
var isChinaUnion = /^(?:13[0-2]|145|15[56]|176|18[56])d{8}$/; //聯通
var isChinaTelcom = /^(?:133|153|177|18[019])d{8}$/; // 電信
var isOtherTelphone = /^170([059])d{7}$/;//其他運營商

var utils = {
checkMobile: function(telphone){
telphone = this.trim(telphone);
if(telphone.length !== 11){
return this.setReturnJson(false, '未檢測到正確的手機號碼');
}
else{
if(isChinaMobile.test(telphone)){
return this.setReturnJson(true, '移動', {name: 'ChinaMobile'});
}
else if(isChinaUnion.test(telphone)){
return this.setReturnJson(true, '聯通', {name: 'ChinaUnion'});
}
else if(isChinaTelcom.test(telphone)){
return this.setReturnJson(true, '電信', {name: 'ChinaTelcom'});
}
else if(isOtherTelphone.test(telphone)){
var num = isOtherTelphone.exec(telphone);
return this.setReturnJson(true, '', {name: ''});
}
else{
return this.setReturnJson(false, '未檢測到正確的手機號碼');
}
}
},
setReturnJson: function(status, msg, data){
if(typeof status !== 'boolean' && typeof status !== 'number'){
status = false;
}
if(typeof msg !== 'string'){
msg = '';
}
return {
'status': status,
'msg': msg,
'data': data
};
}
}
 
<script type="text/javascript">
var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+d{8})$/;// 驗證130-139,150-159,180-189號碼段的手機號碼
if(!myreg.test($("#phone").val()))
{
alert('請輸入有效的手機號碼!');
return false;
}
</script>
function validatemobile(mobile)
{
if(mobile.length==0)
{
alert('請輸入手機號碼!');
document.form1.mobile.focus();
return false;
}
if(mobile.length!=11)
{
alert('請輸入有效的手機號碼!');
document.form1.mobile.focus();
return false;
}

var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+d{8})$/;
if(!myreg.test(mobile))
{
alert('請輸入有效的手機號碼!');
document.form1.mobile.focus();
return false;
}
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved