Java ID 카드 합법성 확인 및 참조에 대한 ID 카드 번호의 유효한 정보를 얻으십시오. 특정 내용은 다음과 같습니다
Java ID 카드 합법성 확인
/** ID 카드의 첫 6 자리 [ABCDEF]는 관리 부문 디지털 코드 (단편의 디지털 코드 참조) 설명 ( "GB/T 2260-2007 중국 인민 공화국의 관리 부문 코드를 참조) :*이 디지털 코드의 편집에 대한 편집자의 원칙과 구조 분석은 (주제가)를 나타내며, 이의 제 3 계층의 직접 입양, 주정부의 조정 (Munightor Congeances), 주정부의 조정을 입양합니다. 중앙 정부, 특수 행정 지역), * 도시 (지역, 자율 현, 리그) 및 카운티 (자율 카운티, 카운티 수준의 도시, 배너, 자율 배너, 지방 자치구, 산림 지역, 특수 지구). 왼쪽에서 오른쪽으로 디지털 코드 코드 구조의 의미는 다음과 같습니다. 첫 번째 계층은 주, 자치 지역, 중앙 정부 바로의 지방 자치 단체 및 특수 행정 지역을 나타내는 AB 2 자리 코드입니다. 두 번째 계층은 지방 자치 단체, 지역, 자율 현, 동맹 및 지방 자치 단체의 요약 코드를 나타내는 CD 2 자리 코드이며, 지방 정부 하의 카운티 수준의 행정 부서의 요약 코드 (자율 지역) (자율 지역)는 다음과 같습니다. —21 ~ 50은 지구, 자율 현, 동맹의 요약 법을 나타냅니다. —90은 지방 (자율 지역) 하의 카운티 수준의 행정 부서의 요약 코드를 나타냅니다. 3 층은 카운티, 자율 카운티, 카운티 수준의 도시, 배너, 자율 배너, 지방 자치 단체, 산림 지역 및 특수 지구를 대표하는 2 개의 EF 자리입니다. 그중 : —01 ~ 20은 도시 관할하에 카운티 수준의 도시를 나타내는 카운티 수준의 도시, 지구 (자율 현, 리그) 및 카운티 수준의 행정 부서 하의 주 (자치 지역)에 따라 카운티 수준의 도시를 나타냅니다. 01은 일반적으로 관할권의 요약 코드를 나타냅니다. —21 ~ 80은 카운티, 자치 카운티, 배너, 자율 배너, 산림 지역 및 지역 특수 지구의 관할하에 카운티 수준의 도시를 나타냅니다. —81 ~ 99는 지방의 관할하에있는 카운티 수준의 도시를 나타냅니다 (자치 지역). */import java.text.parseException; import java.text.simpledateformat; import java.util.calendar; import java.util.date; import java.util.gregoriancalendar; import java.util.hashmap; import java.util.map; import java.util. * 클래스 설명 : ID 카드 적법성 검증 * </p> * <p> * ---- 15 자리 ID 번호 : 7 번째와 8 자리는 출생 연도 (두 자리), 9 번째와 10 자리는 생년월일, 11 및 12 자리는 출생 날짜, 15 자리 숫자는 성별, 홀수 숫자는 여성입니다. * --- 18 자리 ID 번호* : 7, 8, 9 및 10은 생년월일 (4 자리), 11과 12는 생년월일, 13과 14는 생년월일을 나타내며, 17은 성별을 나타내고, 홀수 숫자는 남성이며, 숫자는 여성입니다. * </p> */@suppresswarnings ({ "확인되지 않은", "사용되지 않은", "All"}) 공개 클래스 IdcardValidator {/** * 지방, 시립 코드 테이블 : {11 : "Beijing", 12 : "Tianjin", 13 : "Hebei", 14 : "Shanxi" 22 : "Jilin", 23 : "Heilongjiang", 31 : "Shanghai", 32 : "Jiangsu", * 33 : "Zhejiang", 34 : "Anhui", 35 : "Fujian", 36 : "Jiangxi", 37 : "Shandong", 41 : "Henan", * 42 : "Hubei", 43 : "Hunan", 44 : "Guangdong", 45 : "Guangxi", 46 : "Hainan", 50 : "Chongqing", * 51 : "Sichuan", 52 : "Guizhou", 53 : "Yunnan", "Tibet", 61 : "Shaanxi", 62 : " 63 : "Qinghai", 64 : "Ningxia", 65 : "Xinjiang", 71 : "대만", 81 : "홍콩", 82 : "macao", 91 : "외국"} */ Protected String codeAndCity [] = {{ "11", "Beijing"}, "12", ",", ",", ","12 ","Beijing " "13", "Hebei"}, { "14", "shanxi"}, { "15", "Inner Mongolia"}, { "21", "liaoning"}, { "22", "Jilin"}, { "23", "Heilongjiang"}, { "31", "Shanghai", "31", "31" "Jiangsu"}, { "33", "Zhejiang"}, { "34", "Anhui"}, { "35", "Fujian"}, { "36", "Jiangxi"}, { "37", "Shandong"}, { "41", ""41 "," "41", ""41 ","41 " }, { "43", "hunan"}, { "44", "Guangdong"}, { "45", "Guangxi"}, { "46", "Hainan"}, { "50", "chongqing"}, { "51", "sichuan"}, { "52", "},} "Yunnan"}, { "54", "Tibet"}, { "61", "Shaanxi"}, { "62", "Gansu"}, { "63", "Qinghai"}, { "64", "Ningxia"}, { "65", "xinjang"}, { "71"}, }, { "81", "Hong Kong"}, { "82", "macao"}, { "91", "외국"}}; Private String CityCode [] = { "11", "12", "13", "14", "15", "21", "22", "23", "31", "32", "33", "34", "36", "37", "41", "42", "44", "46", "" "," "," "," ","45 " "52", "53", "54", "61", "62", "63", "64", "65", "71", "81", "82", "91"}; // 각 가중치 계수 개인 int power [] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 7, 9, 10, 5, 8, 4, 2}; // 18 번째 비트 검증 코드 개인 문자열 verifyCode [] = "1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}; / ** * 모든 ID 카드의 합법성을 확인하십시오 * * @param idcard * @return */ public boolean isvalidatedallidcard (String idcard) {if (idcard.length () == 15) {idcard = this.convertidcarby15bit (idcard); } reture this.isvalidate18idcard (idcard); } /** * <p> * 중국 인민 공화국의 국가 표준 GB11643-1999의 시민권 ID 번호 조항에 따라 18 자리 ID 카드 * < /p> *의 합법성을 결정합니다. 시민권 ID 번호는 17 자리 디지털 온톨로지 코드와 1 자리 검증 코드로 구성된 기능 조합 코드입니다. * 배열 순서는 왼쪽에서 오른쪽으로입니다. 6 자리 주소 코드, 8 자리 출생 날짜, 3 자리 시퀀스 코드 및 1 자리 검증 코드입니다. * <p> * 시퀀스 코드 : 동일한 주소 코드로 식별 된 영역 내에서 같은 해, 월 및 일에 태어난 사람들에게 할당 된 시퀀스 번호를 나타냅니다. 시퀀스 코드의 홀수는 남성에게 할당되며 짝수는 여성에게 할당됩니다. * </p> * <p> * 1. 첫 번째 1과 2 자리는 다음을 나타냅니다. 2. 세 번째와 4 자리는 다음을 나타냅니다. 도시의 코드; 3. 5 번째와 6 자리는 다음을 나타냅니다. 지구와 카운티의 코드; * 4. 7 ~ 14 자리는 다음을 나타냅니다 : 연도, 월, 생년월; 5. 15 및 16 자리는 다음을 나타냅니다. * 6. 17 번째 숫자는 성별을 나타냅니다. 홀수 숫자는 남성을 나타내고, 숫자는 여성을 나타냅니다. * 7. 18 번째 숫자는 교정 코드입니다. 일부는 개인 정보 코드라고 말하며, 이는 일반적으로 ID 카드의 정확성을 확인하기 위해 컴퓨터에 의해 무작위로 생성됩니다. 교정 코드는 0에서 9까지의 숫자 일 수 있으며 때로는 x로 표시됩니다. * </p> * <p> * 18 번째 숫자의 계산 방법 (확인 코드)은 다음과 같습니다. 1. 이전 ID 번호의 17 자리 수에 다른 계수를 곱하십시오. 첫 번째 숫자에서 열일곱 번째 숫자로의 계수는 다음과 같습니다. * </p> * <p> * 3. 첨가를 사용하여 11로 나누어 나머지가 무엇인지 확인하십시오. * </p> * 4. 나머지는 11 숫자 만 가질 수 있습니다. 0 1 2 3 4 5 6 7 8 9 10. 각각의 마지막 ID 카드의 수는 1 0 x 9 8 7 6 5 3 * 2. * <p> * 5. 위에서 2 인 경우 로마 숫자는 ID 카드의 18 번째 숫자에 나타납니다. 나머지가 10 인 경우 ID 카드의 마지막 번호는 2입니다. * </ p> * * * @param idcard * @return */ public boolean isvalidate18idcard (String idcard) {// 비 18 비트는 (idcard.length ()! = 18) {return false; } // 처음 17 비트를 가져옵니다. String idcard17 = idcard.substring (0, 17); // 18 번째 문자열을 가져옵니다. idcard18code = idcard.substring (17, 18); char c [] = null; 문자열 checkcode = ""; // 모든 숫자 인 경우 (isdigital (idcard17)) {c = idcard17.tochararray (); } else {return false; } if (ull! = c) {int bit [] = new int [idcard17.length ()]; bit = converChartoint (c); int sum17 = 0; sum17 = getPowersum (비트); // 검증 코드의 나머지를 가져 오려면 11로 합계 값을 확인합니다. checkCode = getCheckCodeBysum (sum17); if (null == checkcode) {return false; } // 계산 된 교정 코드와 ID 카드의 18 번째 비트를 일치시킵니다. 동일하지 않은 경우 (! idcard18code.equalsignorecase (checkcode)) {return false; }} true를 반환합니다. } /*** 15 비트 ID 카드의 합법성을 확인하십시오. 이 방법은 정확하지 않습니다. 판단하기 전에 15 개를 18 비트로 변환하는 것이 가장 좋습니다.이 클래스에서 제공되었습니다. * * @param idcard * @return */ public boolean isvalidate15idcard (string idcard) {// 비 15 비트는 false if (idcard.length ()! = 15) {return false; } // (isdigital (idcard)) {String provinceid = idcard.substring (0, 2); 문자열 생일 = idcard.substring (6, 12); int 년 = integer.parseint (idcard.substring (6, 8)); int month = integer.parseint (idcard.substring (8, 10)); int day = integer.parseint (idcard.substring (10, 12)); // 그것이 법적 지방인지 여부를 결정하십시오. 부울 플래그 = false; for (string id : citycode) {if (id.equals (provinceid)) {flag = true; 부서지다; }} if (! flag) {return false; } //이 ID 카드의 생년월일은 현재 날짜 날짜 이후에 거짓입니다. 출생지 = null; try {birthdate = new simpledateformat ( "yymmdd"). 구문 분석 (생일); } catch (parseException e) {e.printstacktrace (); } if (birthdate == null || new date (). 이전 (birthdate)) {return false; } // 법적 연도 여부를 결정하려면 GregorianCalendar Curday = New GregorianCalendar (); int curyear = curday.get (calendar.year); int year2bit = integer.parseint (string.valueof (curyear) .substring (2)); //} // If (Month <1 || Month> 12) {return false; } // 법적 날짜 여부를 결정하려면 부울 mflag = false; curday.settime (생년월일); //이 ID 카드의 생년월일을 객체 Curday Switch (Month)에 할당 {사례 1 : 사례 3 : 사례 5 : 사례 8 : 사례 10 : 사례 12 : mflag = (day> = 1 && day <= 31); 부서지다; 사례 2 : // Gregorian 달력의 2 월에는 28 일, 도약 2 월에는 29 일이 있습니다. if (curday.isleapyear (curday.get (calendar.year))) {mflag = (day> = 1 && day <= 29); } else {mflag = (day> = 1 && day <= 28); } 부서지다; 사례 4 : 사례 6 : 사례 9 : 사례 11 : mflag = (day> = 1 && day <= 30); 부서지다; } if (! mflag) {return false; }} else {return false; } true를 반환합니다. } / ** * 15 자리 ID 카드를 18 자리 ID 카드로 변환 * @param idcard * @return * / public String convertIdcarby15bit (String idcard) {String idcard17 = null; // 비 15 비트 ID 카드 if (idcard.length ()! = 15) {return null; } if (isdigital (idcard)) {// 생일 날짜를 얻습니다. 생일 = idcard.substring (6, 12); 날짜 생년월일 = null; try {birthdate = new simpledateformat ( "yymmdd"). 구문 분석 (생일); } catch (parseException e) {e.printstacktrace (); } calendar cday = calendar.getInstance (); CDAY.SETTIME (BirthDate); 문자열 년 = String.Valueof (cday.get (calendar.year)); idcard17 = idcard.substring (0, 6) + year + idcard.substring (8); char c [] = idcard17.tochararray (); 문자열 checkcode = ""; if (null! = c) {int bit [] = new int [idcard17.length ()]; // 문자 배열을 정수 배열로 변환 비트 = ConverChartoint (c); int sum17 = 0; sum17 = getPowersum (비트); // 합계 값을 가져 와서 나머지를 가져와 코드 checkCode = getCheckCodeBysum (sum17)을 확인합니다. // (null == checkcode) {return null; } // 18 번째 숫자 체크 코드 IDCARD17 += CheckCode; }} else {// ID 카드에는 숫자 return null이 포함되어 있습니다. } return idcard17; } / ** * 15 비트 및 18 비트 ID 카드 번호의 기본 수치 및 숫자 검증 * * @param idcard * @return * / public boolean isidcard (String idcard) {return idcard == null || "".equals (idcard)? false : matches ( "(^// d {15} $) | (// d {17} (? : // d | x | x) $)", idcard); } / ** * 15 자리 숫자 및 숫자는 15 자리 ID 번호를 확인합니다 * @param idcard * @return * / public boolean is15idcard (String idcard) {return idcard == null || "".equals (idcard)? false : matches ( "^[1-9] // d {7} (0 // d) | (1 [0-2])) ([[0 | 1 | 2] // d) // d) | 3 [0-1]) // d {3} $", idcard); } / ** * 18 자리 ID 번호에 대한 기본 번호 및 숫자 검사 * * @param idcard * @return * / public boolean is18idcard (String idcard) {return pattern .matches ( "^[1-9] // d {5} [1-9] // d {3} ((0 // d) | (1 [0-2])) } / ** * 디지털 검증 * * @param str * @return * / public boolean isdigital (String str) {return str == null || "".equals (str)? false : str.matches ( "^[0-9]*$"); } / ** * ID 카드의 각 비트와 해당 비트의 가중치 계수를 곱한 다음 합계 값 * * @param bit * @return * / public int getPowersum (int [] bit) {int sum = 0; if (power.length! = bit.length) {return sum; } for (int i = 0; i <bit.length; i ++) {for (int j = 0; j <power.length; j ++) {if (i == j) {sum = sum+bit [i] * power [j]; }}} 반환 합; } / ** * 검증 코드에 대한 나머지를 얻으려면 11로 합계 값을 확인하십시오 * @param checkcode * @param sum17 * @return check bit * / public string getCheckCodeBysum (int sum17) {String CheckCode = null; 스위치 (Sum17 % 11) {사례 10 : checkcode = "2"; 부서지다; 사례 9 : checkcode = "3"; 부서지다; 사례 8 : CheckCode = "4"; 부서지다; 사례 7 : CheckCode = "5"; 부서지다; 사례 6 : CheckCode = "6"; 부서지다; 사례 5 : CheckCode = "7"; 부서지다; 사례 4 : CheckCode = "8"; 부서지다; 사례 3 : checkcode = "9"; 부서지다; 사례 2 : checkcode = "x"; 부서지다; 사례 1 : CheckCode = "0"; 부서지다; 사례 0 : CheckCode = "1"; 부서지다; } return checkcode; } / ** * 문자 배열을 정수 배열로 변환 * * @param c * @return * @throws humberformatexception * / public int [] converChartoint (char [] c)는 숫자 formatexception {int [] a = new int [c.length]; int k = 0; for (char temp : c) {a [k ++] = integer.parseint (string.valueof (temp)); } 반환 a; } public static void main (String [] args)은 예외를 {String idcard15 = "142431199001145"; // 15- 비트 String idcard18 = "1212121212121212121212121212"; // 18-bit idcardvalidator iv = new idcardvalidator (); System.out.println (iv.isvalidatedallidcard (idcard15)); System.out.println (iv.isvalidatedallidcard (idcard18)); }}ID 카드 번호를 기반으로 ID 카드와 관련된 정보 추출
import java.text.simpledateformat; import java.util.calendar; import java.util.date; import java.util.gregoriancalendar; import java.util.hashmap; import java.util.map; import java.util.set; * <p> * class */public description : id card와 관련된 정보 추출. idcardinfoextractor {// Private String Province; // City Private String City; // 지구 및 카운티 개인 문자열 지역; // 연도 연도; // 월 개인 INT의 달; // 데이트 비공개 int 데이; // 젠더 개인 문자열 성별; // 생년월일 사적 날짜 생일; 개인지도 <string, String> CityCodemap = new Hashmap <String, String> () {{this.put ( "11", "Beijing"); this.put ( "12", "Tianjin"); this.put ( "13", "Hebei"); this.put ( "14", "shanxi"); this.put ( "15", "Inner Mongolia"); this.put ( "21", "liaoning"); this.put ( "22", "Jilin"); this.put ( "23", "Heilongjiang"); this.put ( "31", "상하이"); this.put ( "32", "jiangsu"); this.put ( "33", "Zhejiang"); this.put ( "34", "anhui"); this.put ( "35", "Fujian"); this.put ( "36", "jiangxi"); this.put ( "37", "Shandong"); this.put ( "41", "Henan"); this.put ( "42", "hubei"); this.put ( "43", "hunan"); this.put ( "44", "Guangdong"); this.put ( "45", "Guangxi"); this.put ( "46", "Hainan"); this.put ( "50", "chongqing"); this.put ( "51", "sichuan"); this.put ( "52", "Guizhou"); this.put ( "53", "yunnan"); this.put ( "54", "Tibet"); this.put ( "61", "Shaanxi"); this.put ( "62", "gansu"); this.put ( "63", "Qinghai"); this.put ( "64", "ningxia"); this.put ( "65", "Xinjiang"); this.put ( "71", "대만"); this.put ( "81", "홍콩"); this.put ( "82", "macao"); this.put ( "91", "외국"); }}; 개인 IdcardValidator validator = null; / *** 생성자를 통해 각 멤버 속성을 초기화*/ public idcardInfoExtractor (String idcard) {try {validator = new idcardValidator (); if (validator.isvalidatedallidcard (idcard)) {if (idcard.length () == 15) {idcard = validator.convertidcarby15bit (idcard); } // 지방 문자열을 가져옵니다. provinceid = idcard.substring (0, 2); <string> key = this.cityCodemap.keyset (); for (string id : key) {if (id.equals (provinceid)) {this.province = this.citycodemap.get (id); 부서지다; }} // 성별 문자열 id17 = idcard.substring (16, 17); if (integer.parseint (id17) % 2! = 0) {this.gender = "male"; } else {this.gender = "여성"; } // 생년월일을 얻습니다. 생일 = idcard.substring (6, 14); 날짜 birthdate = new simpledateformat ( "yyyymmdd") .parse (생일); this.birthday = 생일; GregorianCalendar currentday = New GregorianCalendar (); currentday.settime (Birthdate); this.year = currentday.get (calendar.year); this.month = currentday.get (calendar.month) + 1; this.day = currentday.get (calendar.day_of_month); }} catch (예외 e) {e.printstacktrace (); }} / ** * @return the Province * / public string getProvince () {return province; } / ** * @City * / Public String getCity () {Return City; } / ** * @영역을 return * / public string getRegion () {return region; } / ** * @ERETURN the Year * / public int getyear () {return Year; } / ** * @ @달의 달 * / public int getmonth () {return month; } / ** * @Day * / public int getday () {return day; } / ** * @성별 * / public string getGender () {return gender; } / ** * @생일 * / 공개 날짜 getBirthday () {return birthday; } @override public String toString () {return "province :" + this.province + ", 성별 :" + this.gender + ", 생년월일 :" + this.birthday; } public static void main (String [] args) {String idcard = "1212121212121212121212"; IdcardInfoExtractor IE = New IdcardInfoExtractor (IDCard); System.out.println (예 : ToString ()); }}위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.