Browse Source

身份证校验问题

huangguoce 2 weeks ago
parent
commit
df86c37c57
1 changed files with 4 additions and 3 deletions
  1. 4 3
      src/views/sys/user/UserInfo.vue

+ 4 - 3
src/views/sys/user/UserInfo.vue

@@ -2996,14 +2996,15 @@ export default {
 					let month = myDate.getMonth() + 1
 					let day = myDate.getDate()
 					let age = 0
-
 					if (idCard.length === 18) {
+						let birthMonth = parseInt(idCard.substring(10, 12))
+						let birthDay = parseInt(idCard.substring(12, 14))
 						age = myDate.getFullYear() - idCard.substring(6, 10) - 1
 						sex = idCard.substring(16, 17)
 						birth = idCard.substring(6, 10) + '-' + idCard.substring(10, 12) + '-' + idCard.substring(12, 14)
 						// eslint-disable-next-line no-mixed-operators
-						if (birthMonth < currentMonth ||
-							(birthMonth === currentMonth && birthDay <= currentDay)) {
+						if (birthMonth < month ||
+							(birthMonth === month && birthDay <= day)) {
 							age++;
 						}
 					}