复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>正则表达式验证</title>

    <script type="text/javascript" src="/UploadFiles/2021-04-02/jquery-1.4.1.min.js">    <script type="text/javascript">
        var Validate = {

            isTel: function (s) {
                var patrn = /^((\+?86)|(\(\+86\)))?\d{3,4}-\d{7,8}(-\d{3,4})?$/
                if (!patrn.exec(s)) return false
                return true
            },

            isMobile: function (value) {
                var validateReg = /^((\+?86)|(\(\+86\)))?1\d{10}$/;
                return validateReg.test(value);
            },

            cellPhone: function () {
                var cellPhoneNumber = $("#txtCellPhone").val();
                if (!Validate.isMobile(cellPhoneNumber)) {
                    alert("手机号码格式不正确");
                    return false;
                } else {
                    alert("您的手机号码格式是正确的");
                }
            },

            telePhone: function () {
                var telePhoneNumber = $("#txttelePhone").val();
                if (!Validate.isTel(telePhoneNumber)) {
                    alert("电话号码格式不正确");
                    return false;
                } else {
                    alert("您的电话号码格式是正确的");
                }
            }
        }
    </script>
</head>
<body>
<div>
   <label>请输入手机号码(支持+86):</label><input type="text" id="txtCellPhone" /><input  type="button" value="验证" onclick="Validate.cellPhone();"/><br />
    <label>请输入电话号码(支持+86):</label><input type="text" id="txttelePhone" /><input  type="button" value="验证" onclick="Validate.telePhone();"/><br />
</div>
</body>
</html>

标签:
js验证

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com