首页 > CMS > 帝国Empire > 正文

帝国cms html 验证手机和电话号码是否合法怎么实现?

2024-08-28 12:25:24
字体:
来源:转载
供稿:网友
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>表单验证</title>
<script>
function doValidate() {
        var chineseReg = /^[/u4E00-/u9FA5]{2,4}$/;
        if(!chineseReg.test(document.forma.name.value)) {
                  alert('请填写中文2到4个字!!');
                  document.forma.name.focus();
                  return false;
        }

        var phoneNumReg = /(^[0-9]{3,4}/-[0-9]{7}$)|(^[0-9]{7}$)|(^[0-9]{3,4}[0-9]{7}$)|(^0{0,1}13[0-9]{9}$)/

        if(!phoneNumReg.test(document.forma.phoneNum.value)) {
                  alert('请填写正确电话号码!!');
                  document.forma.phoneNum.focus();
                  return false;
        }
        return true;
}
</script>
</head>
<body>

<form action="" name="forma" onsubmit="return doValidate()">
姓名:<input type="text" name="name" value="姓名"><br />
电话:<input type="text" name="phoneNum"><br />
<input type="submit" value="Submit">
</form>

</body>
</html>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表