Home > Web Front-end > JS Tutorial > js verifies phone number and mobile phone support +86 regular expression

js verifies phone number and mobile phone support +86 regular expression

高洛峰
Release: 2017-01-14 13:17:11
Original
2238 people have browsed it

<!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>
Copy after login

For more js verification phone number and mobile phone support +86 regular expression related articles, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template