日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

vue 身份证验证

發布時間:2023/12/20 vue 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue 身份证验证 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?數據格式

data () {return {show: false,type: 'add',saveLoading: false,dataobj: {name: '', // 姓名idType: '', // 證件類型id: '', // 證件號birthday: '', // 出生日期gender: '', // 性別relations: '', // 關系insuredAmount: '', // 保額paymentMethod: '', // 交費方式期限premium: '' // 保費}}},

?

validateIdCard (id, backInfo) {let info = {y: '1900',m: '01',d: '01',sex: 'male',valid: false,length: 0}if (typeof id !== 'string') return this.back(info, backInfo)// 18if (/^\d{17}[0-9x]$/i.test(id)) {if (!this.initDate(18, info, id)) return this.back(info, backInfo)id = id.toLowerCase().split('')let wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]let y = '10x98765432'.split('')let sum = 0for (let i = 0; i < 17; i++) sum += wi[i] * id[i]if (y[sum % 11] === id.pop().toLowerCase()) info.valid = truereturn this.back(info, backInfo)} else if (/^\d{15}$/.test(id)) { // 15if (this.initDate(15, info, id)) info.valid = truereturn this.back(info, backInfo)} else {return this.back(info, backInfo)}},back (info, backInfo) {return backInfo ? info : info.valid},initDate (length, info, id) {info.length = lengthlet aa = (length === 15) ? 0 : 2 // 15:18let tempinfo.y = (a ? '' : '19') + id.substring(6, 8 + a)info.m = id.substring(8 + a, 10 + a)info.d = id.substring(10 + a, 12 + a)info.sex = id.substring(14, 15 + a) % 2 === 0 ? 'female' : 'male'temp = new Date(info.y, info.m - 1, info.d)return (temp.getFullYear() === info.y * 1) &&(temp.getMonth() + 1 === info.m * 1) &&(temp.getDate() === info.d * 1)},

身份證失去光標事件判斷身份證號是否正確

IdCardBlur () {if (this.validateIdCard(this.dataobj.id)) {if (this.dataobj.id.length === 18) {let borthNumY = this.dataobj.id.substr(6, 4)let borthNumM = this.dataobj.id.substr(10, 2)let borthNumD = this.dataobj.id.substr(12, 2)let SexNum = this.dataobj.id.substr(16, 1)this.dataobj.birthday = borthNumY + '-' + borthNumM + '-' + borthNumDif (SexNum % 2 === 0) {this.dataobj.gender = '1'} else {this.dataobj.gender = '0'}} else if (this.dataobj.id.length === 15) {let borthNumY = this.dataobj.id.substr(6, 2)let borthNumM = this.dataobj.id.substr(8, 2)let borthNumD = this.dataobj.id.substr(10, 2)let SexNum = this.dataobj.id.substr(14, 1)this.dataobj.birthday = '19' + borthNumY + '-' + borthNumM + '-' + borthNumDif (SexNum % 2 === 0) {this.dataobj.gender = '1'} else {this.dataobj.gender = '0'}}} else {console.log('請輸入正確的身份證號')}},

?

總結

以上是生活随笔為你收集整理的vue 身份证验证的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。