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