亲宝软件园·资讯

展开

js验证电话号码与手机支持+86的正则表达式

人气:0

复制代码 代码如下:

<!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="../Scripts/jquery-1.4.1.min.js"></script>
    <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>

加载全部内容

相关教程
猜你喜欢
用户评论