<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[789])-?\d{5}(\d{3}|\*{3})$/.test(this.Trim()));
}
String.prototype.isTel = function() {
return (/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/.test(this.Trim()));
}
function chkForm() {
var content=document.getElementById("content").value;
var username=document.getElementById("username").value;
with(document.form1){
if (tel.value.isMobile()||tel.value.isTel()) {
tel.value = tel.value.Trim();
return true;
} else {
alert("请输入正确的手机号码或电话号码\n\n例如:13916752109或0712-3614072");
tel.focus();
return false;
}
}
}
</script>
转载于:https://www.cnblogs.com/hcxl/p/8321582.html