完美解答 請采納
創(chuàng)新互聯(lián)建站服務項目包括橋東網(wǎng)站建設、橋東網(wǎng)站制作、橋東網(wǎng)頁制作以及橋東網(wǎng)絡營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關系等,向廣大中小型企業(yè)、政府機構等提供互聯(lián)網(wǎng)行業(yè)的解決方案,橋東網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務的客戶以成都為中心已經(jīng)輻射到橋東省份的部分城市,未來相信會繼續(xù)擴大服務區(qū)域并繼續(xù)獲得客戶的支持與信任!
!DOCTYPE?html
html
head
titlejqjquery?當輸入框輸入11位數(shù)字,將自動判斷。/title
meta?charset="UTF-8"?/
script
window.onload?=?function(){
document.getElementById('phone').onkeyup?=?function(){
var?length?=?this.value.length,
state?=?'';
if(length?==?11){
switch(this.value.substr(0,?3)){
case?'130'?:
case?'131'?:
case?'132'?:
case?'155'?:
case?'156'?:
case?'185'?:
case?'186'?:
case?'145'?:
case?'176'?:
state?=?'聯(lián)不通';
break;
case?'133'?:
case?'153'?:
case?'180'?:
case?'181'?:
case?'189'?:
case?'177'?:
state?=?'電不信';
break;
case?'134'?:
case?'135'?:
case?'136'?:
case?'137'?:
case?'138'?:
case?'139'?:
case?'150'?:
case?'151'?:
case?'152'?:
case?'157'?:
case?'158'?:
case?'159'?:
case?'182'?:
case?'183'?:
case?'184'?:
case?'187'?:
case?'188'?:
case?'147'?:
case?'178'?:
state?=?'移不動';
break;
default?:
state?=?'未知號碼段';
}
document.getElementById('phoneState').innerHTML?=?state;
}else?if(length??11){
this.value?=?this.value.substr(0,?11);?//超出11位剪掉
}
}
}
/script
/head
body
input?type="text"?id="phone"?/span?id="phoneState"/span
/body
/html
input?type="text"?id="test"
$(?"#test"?).bind(?"change",?function()?{
if(?this.value.length?!==?10?)?{
alert(?"長度不為10"?);
}
}?);
我已經(jīng)測試通過
直接可以運行:
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
html
head
title/title
script type="text/javascript"
function test() {
var regex = /^[^_][A-Za-z]*[a-z0-9_]*$/ ;
var inputValue = document.getElementById("input_txt").value;
var ret = regex.test(inputValue);
if (ret == true) {
alert("輸入正確");
} else {
alert("輸入錯誤");
}
}
/script
/head
body
input type="text" id="input_txt"/
input type="button" id="input_btn" onclick="test();" value="測 試"/
/body
/html