??<script?src=
"scripts/jquery-1.4.1.js"
?type=
"text/javascript"
></script>??
????????
<script?language=
"javascript"
?type=
"text/javascript"
>??
????????????
/**?
????????????
*?定義驗證各種格式類型的正則表達式對象?
????????????
*/
??????????????
var
?Regexs?=?{??
????????????????
email:?(/^[0-9a-z][0-9a-z\-\_\.]+@([0-9a-z][0-9a-z\-]*\.)+[a-z]{2,}$/i),
//郵箱??
????????????????
phone:?(/^0[0-9]{2,3}[2-9][0-9]{6,7}$/),
//座機手機號碼??
????????????????
ydphpne:?(/^((13[4-9])|(15[012789])|147|182|187|188)[0-9]{8}$/),
//移動手機號碼??
????????????????
allphpne:?(/^((13[0-9])|(15[0-9])|(18[0-9]))[0-9]{8}$/),
//所有手機號碼??
????????????????
ltphpne:?(/^((13[0-2])|(15[56])|(186)|(145))[0-9]{8}$/),
//聯通手機號碼??
????????????????
dxphpne:?(/^((133)|(153)|(180)|(189))[0-9]{8}$/),
//電信手機號碼??
????????????????
url:?(/^http:\/\/([0-9a-z][0-9a-z\-]*\.)+[a-z]{2,}(:\d+)?\/[0-9a-z%\-_\/\.]+/i),
//網址??
????????????????
num:?(/[^0-9]/),
//數字??
????????????????
cnum:?(/[^0-9a-zA-Z_.-]/),??
????????????????
photo:?(/\.jpg$|\.jpeg$|\.gif$/i),
//圖片格式??
???????????????????????? photo:?(/\.(jpe?g|gif)$/i),//圖片格式(更優)
????????????????
row:?(/\n/ig)??
????????????
};??
????????????
/**?
????????????
*?@return?若符合對應的格式,返回true,否則返回false?
????????????
*/
??????????????
function
?chkFormat(str,?ftype)?{??
????????????????
var
?nReg?=?Regexs[ftype];??
????????????????
if
?(str?==?
null
?||?str?==?
""
)?
return
?false
;?
//輸入為空,認為是驗證通過??
????????????????
if
?(ftype?==?
'num'
)?{??
????????????????????
if
?(!nReg.test(str)?&&?!chkChinese(str))?{
//10.23?tenfy?必須為數字且不能有中文??
????????????????????????
return
?true
;??
????????????????????
}?
else
?{??
????????????????????????
return
?false
;??
????????????????????
}??
????????????????
}??
????????????????
if
?(!nReg.test(str))?{??
????????????????????
return
?true
;??
????????????????
}?
else
?{??
????????????????????
return
?false
;??
???????
?????????????????
}??
????????????
};??
????????????
function
?chkChinese(s)?{??
????????????????
for
?(
var
?i?=?0;?i?<?s.length;?i++)?{??
????????????????????
if
?(s.charCodeAt(i)?>?255)?
return
?true
;??
????????????????
}??
????????????????
return
?false
;??
????????????
};??
????????
</script>??
1 2 3 4 | ???? < input ?value = "" ?type = "text" ?id = "txt_val" ?/>?? ???????? < br ?/>?? ???????? < input ?value = "驗證" ?type = "button" ?onclick = "return?chkFormat($('#txt_val').val(),'email')" /> |