<html>
<head>
<title>js
正则表达式</title>
</head>
<body>
<script LANGUAGE="
javascript">
//匹配固定电话或小灵通,例如:031185907468或02185907468格式
function isphone1(){
var num = document.getElementById('ph').value;
var partten = /^0(([1-9]d)|([3-9]d{2}))d{8}$/;
if(partten.test(num)){
alert('是电话号码');
}else{
alert('不是电话号码');
}
}
function isphone2(){
var num = document.getElementById('mb').value;
var partten = /^1[3,5]d{9}$/;
if(partten.test(num)){
alert('是手机号码');
}else{
alert('不是手机号码');
}
}
</script>
请输入固定电话或小灵通号码:<input type="text" name="phone" id="ph"><input type="button" value="测试" onclick="isphone1();">
请输入手机号码:<input type="text" name="phone" id="mb"><input type="button" value="测试" onclick="isphone2();">
</body>
</html>