JS超强判断电话号码
<script type="text/javascript">
String.prototype.Trim = function() {
var m = this.match(/^\s*(\S+(\s+\S+)*)\s*$/);
return (m == null) ? "" : m[1];
}
String.prototype.isMobile = function() {
return (/^(?:13\d|15[89])-?\d{5}(\d{3}|\*{3})$/.test(this.Trim()));
}
String.prototype.isTel = function()
{
//"兼容格式: 国家代码(2到3位)-区号(2到3位)-电话号码(7到8位)-分机号(3位)"
//return (/^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/.test(this.Trim()));
return (/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/.test(this.Trim()));
}
function chkForm() {
with(document.form_1){
if (tel_1.value.isMobile()||tel_1.value.isTel()) {
tel_1.value = tel_1.value.Trim();
//alert("您的电话/手机号码是:" + tel.value);
return true;
}
else if(form_1.Name_1.value=="")
{
alert("请填写您的姓名");
return false;
}
<!------------------------------------------------------------------------------------------------------------------------->
else {
alert("请输入正确的手机号码或电话号码");
tel_1.focus();
return false;
}
}
}
</script>
<form method="post" name="form_1" >
<table width="288" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="76" align="center" valign="middle">姓名:</td>
<td width="109"><span class="from">
<input name="Name_1" class="from_bd3" style="" size="15" />
</span></td>
<td width="81" rowspan="2" align="center" valign="middle"><input type="image" border="0" src="images/wysq.gif" value="#" οnclick="return chkForm()"/></td>
</tr>
<tr>
<td align="center" valign="middle">手机号:</td>
<td><span class="from">
<input name="tel_1" type="text" class="from_bd" id="cm_xm2" size="15" />
</span></td>
</tr>
</table>
</form>