1、在main.js中

import IdCard from '../static/js/IdCard'
Vue.prototype.validid = IdCard;

2、使用

console.log( this.validid.cnid('110101199003079593') )   //true

3、IdCard.js

// Generated by CoffeeScript 1.12.7/*Validid is open source in:https://github.com/Edditoria/valididunder MIT license:https://github.com/Edditoria/validid/blob/master/LICENSE.md*/(function() {var Validid, validid;Validid = (function() {function Validid() {}Validid.prototype.tools = {normalize: function(id) {var re;re = /[-\/\s]/g;id = id.toUpperCase().replace(re, '');re = /\([A-Z0-9]\)$/;if (re.test(id)) {id = id.replace(/[\(\)]/g, '');}return id;},isDateValid: function(idDate, minDate, maxDate) {var isFormatValid, parseDate;if (minDate == null) {minDate = 'default';}if (maxDate == null) {maxDate = 'today';}if (minDate === 'default' || minDate === '') {minDate = '18991129';}isFormatValid = function(date) {return typeof date === 'string' && /^[0-9]{8}$/.test(date);};if (!isFormatValid(idDate)) {return false;}if (!isFormatValid(minDate)) {return false;}parseDate = function(input) {var date, day, isDayValid, isFutureDate, isLeapYear, isMonthValid, maxDay, month, startIndex, year;startIndex = 0;year = +input.substring(startIndex, startIndex += 4);month = input.substring(startIndex, startIndex += 2);day = +input.substring(startIndex, startIndex += 2);date = new Date(year, +month - 1, day);maxDay = '01,03,05,07,08,10,12'.indexOf(month) >= 0 ? 31 : '04,06,09,11'.indexOf(month) >= 0 ? 30 : (isLeapYear = (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0), isLeapYear ? 29 : 28);isDayValid = day > 0 && day <= maxDay;if (!isDayValid) {return false;}isMonthValid = +month > 0 && +month <= 12;if (!isMonthValid) {return false;}isFutureDate = new Date() < date;if (isFutureDate) {return false;}return date;};idDate = parseDate(idDate);if (idDate === false) {return false;}minDate = parseDate(minDate);if (minDate === false) {return false;}maxDate = maxDate === 'today' ? new Date() : typeof maxDate === 'string' ? parseDate(maxDate) : maxDate;if (maxDate === false) {return false;}return (idDate >= minDate) && (idDate <= maxDate);},getMaxDate: function(yearsOld) {var now, year;now = new Date();year = now.getFullYear() - yearsOld;return new Date(year, now.getMonth(), now.getDate());}};Validid.prototype.cnid = function(id) {var isChecksumValid, isDateValid, isFormatValid, isLengthValid;isLengthValid = function(id) {return id.length === 18;};isFormatValid = function(id) {return /^[0-9]{17}[0-9X]$/.test(id);};isDateValid = (function(_this) {return function() {return _this.tools.isDateValid(id.substring(6, 14), '18860625');};})(this);isChecksumValid = function(id) {var char, checkDigit, getWeight, i, identifier, index, len, remainder, weightedSum;identifier = id.slice(0, -1);checkDigit = id.slice(-1) === 'X' ? 10 : +id.slice(-1);getWeight = function(n) {return Math.pow(2, n - 1) % 11;};weightedSum = 0;index = id.length;for (i = 0, len = identifier.length; i < len; i++) {char = identifier[i];weightedSum += +char * getWeight(index);index--;}remainder = (12 - weightedSum % 11) % 11 - checkDigit;return remainder === 0;};id = this.tools.normalize(id);return isLengthValid(id) && isFormatValid(id) && isDateValid() && isChecksumValid(id);};Validid.prototype.twid = function(id) {var isChecksumValid, isFormatValid, isLengthValid;isLengthValid = function(id) {return id.length === 10;};isFormatValid = function(id) {return /^[A-Z][12][0-9]{8}$/.test(id);};isChecksumValid = function(id) {var char, i, idLen, idTail, len, letterIndex, letterValue, letters, remainder, weight, weightedSum;idLen = id.length;letters = 'ABCDEFGHJKLMNPQRSTUVXYWZIO';letterIndex = letters.indexOf(id[0]) + 10;letterValue = Math.floor(letterIndex / 10) + (letterIndex % 10) * (idLen - 1);idTail = id.slice(1);weight = idLen - 2;weightedSum = 0;for (i = 0, len = idTail.length; i < len; i++) {char = idTail[i];weightedSum += +char * weight;weight--;}remainder = (letterValue + weightedSum + +id.slice(-1)) % 10;return remainder === 0;};id = this.tools.normalize(id);return isLengthValid(id) && isFormatValid(id) && isChecksumValid(id);};Validid.prototype.hkid = function(id) {var getLetterValue, isChecksumValid, isFormatValid, isLengthValid, isLetter;getLetterValue = function(letter) {return letter.charCodeAt(0) - 64;};isLetter = function(char) {return /[a-zA-Z]/.test(char);};isLengthValid = function(id) {return id.length === 8 || id.length === 9;};isFormatValid = function(id) {return /^[A-MP-Z]{1,2}[0-9]{6}[0-9A]$/.test(id);};isChecksumValid = function(id) {var char, charValue, checkDigit, i, identifier, len, remainder, weight, weightedSum;weight = id.length;weightedSum = 0;identifier = id.slice(0, -1);checkDigit = id.slice(-1) === 'A' ? 10 : +id.slice(-1);for (i = 0, len = identifier.length; i < len; i++) {char = identifier[i];charValue = isLetter(char) ? getLetterValue(char) : +char;weightedSum += charValue * weight;weight--;}remainder = (weightedSum + checkDigit) % 11;return remainder === 0;};id = this.tools.normalize(id);return isLengthValid(id) && isFormatValid(id) && isChecksumValid(id);};Validid.prototype.krid = function(id) {var isChecksumValid, isDateValid, isFormatValid, isLengthValid;isLengthValid = function(id) {return id.length === 13;};isFormatValid = function(id) {return /^[0-9]{13}$/.test(id);};isDateValid = (function(_this) {return function(id) {var date, maxDate, sDigit, yearPrefix;sDigit = id.substring(6, 7);yearPrefix = (function() {switch (sDigit) {case '1':case '2':case '5':case '6':return '19';case '3':case '4':case '7':case '8':return '20';default:return '18';}})();date = yearPrefix + id.substring(0, 6);maxDate = _this.tools.getMaxDate(17);return _this.tools.isDateValid(date, 'default', maxDate);};})(this);isChecksumValid = function(id) {var char, i, index, len, remainder, weight, weightedSum;weight = [2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 0];weightedSum = 0;index = 0;for (i = 0, len = id.length; i < len; i++) {char = id[i];weightedSum += +char * weight[index];index++;}remainder = (11 - weightedSum % 11) % 10 - +id.slice(-1);return remainder === 0;};id = this.tools.normalize(id);return isLengthValid(id) && isFormatValid(id) && isDateValid(id) && isChecksumValid(id);};return Validid;})();validid = new Validid();if ((typeof module !== "undefined" && module !== null) && module.exports) {module.exports = validid;}if (typeof window !== "undefined" && window !== null) {window.validid = validid;}}).call(this);

转自: https://blog.csdn.net/qq_37330613/article/details/84973877

Vue 身份证验证大全相关推荐

  1. 身份证验证大全-javascript

    (function($) {$(function() {var ACCEPT = ""; // 检查通过是返回的的成功标识字符串var EIGHTEEN_IDCARD = 18; ...

  2. python验证身份证号码大全_身份证号码处理技巧大全

    身份证号码处理技巧大全,汇总了常用的身份证号码处理六大技巧: 不需要复杂的公式,点点鼠标即可完成,简单快捷,下面将详细介绍六大功能的具体用法.(文章最后有工具和演示文件的下载地址,可以下载下来同步操作 ...

  3. vue+elementui身份证验证

    1.js // 身份证验证isCardID (rule, value, callback) {console.log(value)if (!/(^\d{15}$)|(^\d{17}(\d|X|x)$) ...

  4. javascript 表单验证大全(一)

    javascript 表单验证大全(一) 5.身份证验证:包括15位和18位.function idNumber(s)//身份证验证 {regu1=/^[1-9]\d{7}((0\d)|(1[0-2] ...

  5. js中正则表达式验证_js正则表达式验证大全(收集)

    本篇文章给大家分享js正则表达式验证大全,平时收集的知识,比较全面,需要的朋友可以参考下 以下函数调用方式: function check() { var bb = document.getEleme ...

  6. VUE正则表达式验证规则合集

    VUE正则表达式验证规则合集 0-100校验 发动机号校验 拼音校验 经度校验 纬度校验 VIN码校验 车牌校验 时间校验 票价校验 身份证校验 年龄校验 0-10校验 驾驶证档案编号校验 手机号码校 ...

  7. [vue] prop验证的type类型有哪几种?

    [vue] prop验证的type类型有哪几种? props:{title:String,likes: Number,isPublished: Boolean,commentIds: Array,au ...

  8. 前端js正则验证大全(一套完整的正则验证解决方案)@莫成尘

    先看代码,复制使用即可,验证基于前端常用的正则验证而来.(个人习惯用驼峰命名,请见谅) 如您满意请给莫成尘点个Fabulous 手机号验证 思路是以1开头的第二位是23456789,匹配数字字符9位并 ...

  9. Js中身份证验证及社会统一信用代码验证

    二代身份证验证规则如下: //函数参数必须是字符串,因为二代身份证号码是十八位,而在javascript中,十八位的数值会超出计算范围,造成不精确的结果,导致最后两位和计算的值不一致,从而该函数出现错 ...

最新文章

  1. AI大佬“互怼”:Bengio和Gary Marcus隔空对谈深度学习发展现状
  2. JDBC读取新插入Oracle数据库Sequence值的5种方法
  3. 交易系统单服务器tps,交易者必看!一文了解TPS量化交易系统
  4. #1300 : 展胜地的鲤鱼旗(dp)
  5. Android Lifecycle 生命周期组件详解
  6. 网站常见漏洞-- XSS攻击
  7. 【SQL那些事】事务
  8. java jsr305_java – 为什么我需要添加神器JSR305才能使用Guava 14?
  9. 往届选手心得分享:腾讯广告算法大赛萌新指南
  10. 使用AD将Gerbera文件转化为PCB文件的那些事
  11. Linux里面qt的可执行文件在命令行中可以打开,双击可执行文件打不开
  12. 羊台山西丽路线登山记
  13. HTN规划 jshop2
  14. 学习笔记-echarts自定义背景图片
  15. 计算机应用决策支持系统,决策支持系统
  16. 银行信贷系统调用链路和每个系统的作用
  17. 2012搜狗校园招聘笔试题
  18. zygote--system_server
  19. pix2pix解析以及pytorch实现
  20. ios 表情各大编码对照表

热门文章

  1. Swift 会成为 2022 年十大流行编程语言之一么?
  2. html图片 3d切换特效,一款基于css3的3D图片翻页切换特效
  3. 飞行堡垒7可不可以linux系统,ubuntu18 安装坑点记录(华硕飞行堡垒),华硕飞行堡垒7配置...
  4. JavaWeb12(域对象EL表达式JSTL)
  5. 分享给新手的18条冲压生产经验
  6. 适合Python 的5大练手项目,你练了么?
  7. 龙泉正规的计算机学校有哪些,龙泉正规高铁乘务学校排名榜
  8. shardingsphere+dynamic+mybatisPlugs配置多数据源
  9. 查询上周五到本周四以及同比时间
  10. 【ChatGPT】《Azure OpenAI 服务 - 提示工程简介》- 知识点目录