`
lanqy
  • 浏览: 13778 次
  • 性别: Icon_minigender_1
  • 来自: 柳州
社区版块
存档分类
最新评论

手机号码的验证

阅读更多

<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()));
}

function chkForm(oForm) {
  if (oForm.tel.value.isMobile())  {
    oForm.tel.value=oForm.tel.value.Trim();
    return true;
  } else {
    alert("请输入正确的手机号码!");
  }
  return false;
}
</script>
</head>
<body>
<form name="form1" method="post" action="" onsubmit="return chkForm(this);">
<input type="text" name="tel" value="15812345678" size="30" /><input type="submit" value="提交" />
</form>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics