UNPKG

haw-utils

Version:

一个基于业务场景的工具方法库

51 lines (48 loc) 1.34 kB
(function (global, factory) { if (typeof define === "function" && define.amd) { define(["exports"], factory); } else if (typeof exports !== "undefined") { factory(exports); } else { var mod = { exports: {} }; factory(mod.exports); global.isIdCard = mod.exports; } })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports) { "use strict"; Object.defineProperty(_exports, "__esModule", { value: true }); _exports["default"] = void 0; // 18位身份证 var regIdCard18 = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[012]))(([0-2][1-9])|10|20|30|31)\d{3}(\d|X)$/i; // 15位身份证 var regIdCard15 = /^[1-9]\d{5}\d{2}((0[1-9])|(1[012]))(([0-2][1-9])|10|20|30|31)\d{3}$/; /** * 检测值是否为身份证号 * * @static * @alias module:Validator.isIdCard * @since 1.1.0 * @param {String} value 要检测的值 * @returns {Boolean} 值是否为身份证号 * @example * * isIdCard('320311770706001'); * // => true * * isIdCard('130701199310302288'); * // => true * * isIdCard('130701199310'); * // => false * */ function isIdCard(value) { return regIdCard18.test(value) || regIdCard15.test(value); } var _default = isIdCard; _exports["default"] = _default; });