Js正則表達(dá)式問(wèn)題
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>正則表達(dá)式</title>
<script>
?function checkTel(){
var str=form1.tel.value;//獲取電話(huà)號(hào)碼
var objExp=/^((\d{3}-)?\d{8})&|^((\d{4}-)?\d{7,8})&/;//正則表達(dá)式第一種三位區(qū)號(hào)加-號(hào)加八位數(shù)字電話(huà)號(hào)碼
if(objExp.test(str)==true){
alert("您輸入的電話(huà)號(hào)碼合法");
}
else{
alert("您輸入的電話(huà)號(hào)碼不合法");
}
?
};
</script>
</head>
<body>
<form name="form1" method="post" action="">
? 請(qǐng)輸入電話(huà)號(hào)碼:<input type="text" name="tel" id="tel"/>
? ? ? ? ? ? ? ? <input type="button" value="檢測(cè)" onClick="checkTel()"/>
</form>
</body>
</html>
各位大神看看,不管我輸入什么格式的電話(huà)號(hào)碼 都是顯示“不合法”
2016-08-03
應(yīng)該是表達(dá)式錯(cuò)了,參考一下http://www.cnblogs.com/jihua/archive/2012/09/28/yanzheng.html