目錄
一、身份证结构和形式
二、 18位身份证号码计算方法
三、JAVA 校验身份证号码
补充:java开发身份证号校验(边输入边校验)
首頁 Java java教程 如何用JAVA驗證身分證號碼有效性

如何用JAVA驗證身分證號碼有效性

Apr 17, 2023 pm 10:01 PM
java

一、身份证结构和形式

在通用的身份证号码有15位的和18位的;

15位身份证号码各位的含义:

1、1-2位省、自治区、直辖市代码;

2、3-4位地级市、盟、自治州代码;

3、5-6位县、县级市、区代码;

4、7-12位出生年月日,比如670401代表1967年4月1日,与18位的第一个区别;

5、13-15位为顺序号,其中15位男为单数,女为双数;

18位身份证号码各位的含义:

1、 1-2位表示省(自治区、直辖市、特别行政区)。

2、 3-4位表示市(地区、自治州、盟及国家直辖市所属市辖区和县的汇总码)。其中,01-20,51-70表示省直辖市;21-50表示地区(自治州、盟)。

3、 5-6位表示县(市辖区、县级市、旗)。01-18表示市辖区或地区(自治州、盟)辖县级市;21-80表示县(旗);81-99表示省直辖县级市。

4、 7-14位【生日期码】表示编码对象出生的年、月、日,其中年份用四位数字表示,年、月、日之间不用分隔符。例如:1981年05月11日就用19810511表示。

5、 15-17位【顺序码】表示地址码所标识的区域范围内,对同年、月、日出生的人员编定的顺序号。其中第十七位奇数分给男性,偶数分给女性。

6、 18位【校验码】,作为尾号的校验码,是由号码编制单位按统一的公式计算出来的,如果某人的尾号是0-9,都不会出现X,但如果尾号是10,那么就得用X来代替,因为如果用10做尾号,那么此人的身份证就变成了19位,而19位的号码违反了国家标准,并且中国的计算机应用系统也不承认19位的身份证号码。Ⅹ是罗马数字的10,用X来代替10,可以保证公民的身份证符合国家标准。

二、 18位身份证号码计算方法

1、将前面的身份证号码17位数分别乘以不同的系数。从第一位到第十七位的系数分别为:7-9-10-5-8-4-2-1-6-3-7-9-10-5-8-4-2。

2、将这17位数字和系数相乘的结果相加。

3、用加出来和除以11,看余数是多少?

4、余数只可能有0-1-2-3-4-5-6-7-8-9-10这11个数字。其分别对应的最后一位身份证的号码为1-0-X -9-8-7-6-5-4-3-2。

5、通过上面得知如果余数是3,就会在身份证的第18位数字上出现的是9。如果对应的数字是2,身份证的最后一位号码就是罗马数字x。

例如:某男性的身份证号码为【53010219200508011x】, 我们看看这个身份证是不是合法的身份证。
首先我们得出前17位的乘积和【(57)+(39)+(010)+(15)+(08)+(24)+(12)+(91)+(26)+(03)+(07)+(59)+(010)+(85)+(08)+(14)+(1*2)】是189,然后用189除以11得出的结果是189/11=17----2,也就是说其余数是2。最后通过对应规则就可以知道余数2对应的检验码是X。所以,可以判定这是一个正确的身份证号码。

以上部分内容来自百度百科

三、JAVA 校验身份证号码

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

package cn.wje.internationa;

 

import java.text.DateFormat;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

import java.util.HashMap;

import java.util.Map;

import java.util.regex.Pattern;

 

/**

 * @author QiFeng·Luo

 */

public class IdCardUtil {

 

    /**

     * 数字

     */

    public final static Pattern NUMBERS = Pattern.compile("\\d+");

 

    /**

     * 中国公民身份证号码最小长度。

     */

    private static final int CHINA_ID_MIN_LENGTH = 15;

 

    /**

     * 中国公民身份证号码最大长度。

     */

    private static final int CHINA_ID_MAX_LENGTH = 18;

 

    public static Exception isValidatedAllIdcard(String idcard) throws Exception {

        boolean ret = isIdcard(idcard);

        if (!ret) {

            throw new Exception("身份证格式有误");

        }

        return null;

    }

 

    final static Map<Integer, String> zoneNum = new HashMap<>();

    /**

     * 身份证省份编码

     * */

    static {

        zoneNum.put(11, "北京");

        zoneNum.put(12, "天津");

        zoneNum.put(13, "河北");

        zoneNum.put(14, "山西");

        zoneNum.put(15, "内蒙古");

        zoneNum.put(21, "辽宁");

        zoneNum.put(22, "吉林");

        zoneNum.put(23, "黑龙江");

        zoneNum.put(31, "上海");

        zoneNum.put(32, "江苏");

        zoneNum.put(33, "浙江");

        zoneNum.put(34, "安徽");

        zoneNum.put(35, "福建");

        zoneNum.put(36, "江西");

        zoneNum.put(37, "山东");

        zoneNum.put(41, "河南");

        zoneNum.put(42, "湖北");

        zoneNum.put(43, "湖南");

        zoneNum.put(44, "广东");

        zoneNum.put(45, "广西");

        zoneNum.put(46, "海南");

        zoneNum.put(50, "重庆");

        zoneNum.put(51, "四川");

        zoneNum.put(52, "贵州");

        zoneNum.put(53, "云南");

        zoneNum.put(54, "西藏");

        zoneNum.put(61, "陕西");

        zoneNum.put(62, "甘肃");

        zoneNum.put(63, "青海");

        zoneNum.put(64, "宁夏");

        zoneNum.put(65, "新疆");

        zoneNum.put(71, "台湾");

        zoneNum.put(81, "香港");

        zoneNum.put(82, "澳门");

        zoneNum.put(91, "国外");

    }

 

    /**

     * 校验码

     */

    final static int[] PARITYBIT = { '1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2' };

 

    /**

     * 加权因子wi

     */

    final static int[] POWER_LIST = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };

 

    /**

     * 验证身份证号有效性

     *

     * @param idCard:身份证号

     * @return true/false

     */

    public static boolean isIdcard(String idCard) {

        // 号码长度应为15位或18位

        if (idCard == null || (idCard.length() != 15 && idCard.length() != 18)) {

            return false;

        }

        // 校验区位码

        if (!zoneNum.containsKey(Integer.valueOf(idCard.substring(0, 2)))) {

            return false;

        }

        // 校验年份

        String year = idCard.length() == 15 ? "19" + idCard.substring(6, 8) : idCard.substring(6, 10);

        final int iyear = Integer.parseInt(year);

        if (iyear < 1900 || iyear > Calendar.getInstance().get(Calendar.YEAR)) {

            // 1900年的PASS,超过今年的PASS

            return false;

        }

        // 校验月份

        String month = idCard.length() == 15 ? idCard.substring(8, 10) : idCard.substring(10, 12);

        final int imonth = Integer.parseInt(month);

        if (imonth < 1 || imonth > 12) {

            return false;

        }

        // 校验天数

        String day = idCard.length() == 15 ? idCard.substring(10, 12) : idCard.substring(12, 14);

        final int iday = Integer.parseInt(day);

        if (iday < 1 || iday > 31) {

            return false;

        }

        // 校验一个合法的年月日

        if (!isValidDate(year + month + day)) {

            return false;

        }

        // 校验位数

        int power = 0;

        final char[] cs = idCard.toUpperCase().toCharArray();

        for (int i = 0; i < cs.length; i++) {// 循环比正则表达式更快

            if (i == cs.length - 1 && cs[i] == 'X') {

                break;// 最后一位可以是X或者x

            }

            if (cs[i] < '0' || cs[i] > '9') {

                return false;

            }

            if (i < cs.length - 1) {

                power += (cs[i] - '0') * POWER_LIST[i];

            }

        }

        // 校验“校验码”

        if (idCard.length() == 15) {

            return true;

        }

        return cs[cs.length - 1] == PARITYBIT[power % 11];

    }

 

    /**

     * 判断字符串是否为日期格式(合法)

     *

     * @param inDate:字符串时间

     * @return true/false

     */

    public static boolean isValidDate(String inDate) {

        if (inDate == null) {

            return false;

        }

        // 或yyyy-MM-dd

        SimpleDateFormat dataFormat = new SimpleDateFormat("yyyyMMdd");

        if (inDate.trim().length() != dataFormat.toPattern().length()) {

            return false;

        }

        // 该方法用于设置Calendar严格解析字符串;默认为true,宽松解析

        dataFormat.setLenient(false);

        try {

            dataFormat.parse(inDate.trim());

        } catch (ParseException e) {

            return false;

        }

        return true;

    }

 

    /**

     * 转换成日期

     * @param birthday

     * @return

     */

    private static Date toBirthDay(String birthday){

        try{

            Calendar calendar = Calendar.getInstance();

            calendar.set(Calendar.YEAR, Integer.parseInt(birthday.substring(0, 4)));

            // 月份从0开始,所以减1

            calendar.set(Calendar.MONTH, Integer.parseInt(birthday.substring(4, 6)) - 1);

            calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(birthday.substring(6, 8)));

            // 以下设置时分秒,但是对生日的意义不大

            calendar.set(Calendar.HOUR_OF_DAY, 0);

            calendar.set(Calendar.MINUTE, 0);

            calendar.set(Calendar.SECOND, 0);

            calendar.set(Calendar.MILLISECOND, 0);

 

            return calendar.getTime();

        }catch (Exception e){

            return null;

        }

    }

 

    /**

     * 给定内容是否匹配正则

     *

     * @param pattern 模式

     * @param content 内容

     * @return 正则为null或者""则不检查,返回true,内容为null返回false

     */

    private static boolean isMatch(Pattern pattern, CharSequence content) {

        if (content == null || pattern == null) {

            // 提供null的字符串为不匹配

            return false;

        }

        return pattern.matcher(content).matches();

    }

 

    /**

     * 将字符串转换成指定格式的日期

     *

     * @param str        日期字符串.

     * @param dateFormat 日期格式. 如果为空,默认为:yyyy-MM-dd HH:mm:ss.

     * @return

     */

    private static Date strToDate(final String str, String dateFormat) {

        if (str == null || str.trim().length() == 0) {

            return null;

        }

        try {

            if (dateFormat == null || dateFormat.length() == 0) {

                dateFormat = "yyyy-MM-dd HH:mm:ss";

            }

            DateFormat fmt = new SimpleDateFormat(dateFormat);

            return fmt.parse(str.trim());

        } catch (Exception ex) {

            return null;

        }

    }

 

    /**

     * 根据日期获取年

     *

     * @param date 日期

     * @return 年的部分

     */

    public static int year(Date date) {

        Calendar ca = Calendar.getInstance();

        ca.setTime(date);

        return ca.get(Calendar.YEAR);

    }

 

    /**

     * 将power和值与11取模获得余数进行校验码判断

     *

     * @param iSum 加权和

     * @return 校验位

     */

    private static char getCheckCode18(int iSum) {

        switch (iSum % 11) {

            case 10:

                return '2';

            case 9:

                return '3';

            case 8:

                return '4';

            case 7:

                return '5';

            case 6:

                return '6';

            case 5:

                return '7';

            case 4:

                return '8';

            case 3:

                return '9';

            case 2:

                return 'x';

            case 1:

                return '0';

            case 0:

                return '1';

            default:

                return ' ';

        }

    }

 

    /**

     * 获得18位身份证校验码

     * 计算方式:

     * 将前面的身份证号码17位数分别乘以不同的系数。从第一位到第十七位的系数分别为:7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2

     * 将这17位数字和系数相乘的结果相加

     * 用加出来和除以11,看余数是多少

     * 余数只可能有0 1 2 3 4 5 6 7 8 9 10这11个数字。其分别对应的最后一位身份证的号码为1 0 X 9 8 7 6 5 4 3 2

     * 通过上面得知如果余数是2,就会在身份证的第18位数字上出现罗马数字的Ⅹ。如果余数是10,身份证的最后一位号码就是2

     * @param code17 18位身份证号中的前17位

     * @return 第18位

     */

    private static char getCheckCode18(String code17) {

        int sum = getPowerSum(code17.toCharArray());

        return getCheckCode18(sum);

    }

 

    /**

     * 将身份证的每位和对应位的加权因子相乘之后,再得到和值

     *

     * @param iArr 身份证号码的数组

     * @return 身份证编码

     */

    private static int getPowerSum(char[] iArr) {

        int iSum = 0;

        if (POWER_LIST.length == iArr.length) {

            for (int i = 0; i < iArr.length; i++) {

                iSum += Integer.valueOf(String.valueOf(iArr[i])) * POWER_LIST[i];

            }

        }

        return iSum;

    }

 

    /**

     * 将15位身份证号码转换为18位

     *

     * @param idCard 15位身份编码

     * @return 18位身份编码

     */

    public static String convertIdCard(String idCard) {

        StringBuilder idCard18;

        if (idCard.length() != CHINA_ID_MIN_LENGTH) {

            return null;

        }

        if (isMatch(NUMBERS, idCard)) {

            // 获取出生年月日

            String birthday = idCard.substring(6, 12);

            Date birthDate = strToDate(birthday, "yyMMdd");

            // 获取出生年

            int sYear = year(birthDate);

            // 理论上2000年之后不存在15位身份证,可以不要此判断

            if (sYear > 2000) {

                sYear -= 100;

            }

            idCard18 = new StringBuilder().append(idCard, 0, 6).append(sYear).append(idCard.substring(8));

            // 获取校验位

            char sVal = getCheckCode18(idCard18.toString());

            idCard18.append(sVal);

        } else {

            return null;

        }

        return idCard18.toString();

    }

 

    /**

     * 从身份证号码中获取生日

     * @param idno

     * @return null表示idno错误,未获取到生日

     */

    public static Date getBirthDay(String idno){

        if(!isIdcard(idno)){

            return null;

        }

        if (idno.length() == 15) {

            // 如果是15位转为18位

            idno = convertIdCard(idno);

        }

        return toBirthDay(idno.substring(6, 14));

    }

 

    /**

     * 从身份证号码中获取生日

     * @param idno

     * @return null表示idno错误,未获取到生日 日期格式为:yyyy-MM-dd

     */

    public static String getBirthDayStr(String idno){

        if(!isIdcard(idno)){

            return null;

        }

        if (idno.length() == 15) {

            // 如果是15位转为18位

            idno = convertIdCard(idno);

        }

        Date birthday = toBirthDay(idno.substring(6, 14));

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

        return simpleDateFormat.format(birthday);

    }

    /**

     * 从身份证号中获取性别

     * @param idno

     * @return 0:男,1:女,-1:证件号码错误

     */

    public static String getGender(String idno){

        if(!isIdcard(idno)){

            return "-1";

        }

        if (idno.length() == 15) {

            // 如果是15位转为18位

            idno = convertIdCard(idno);

        }

        // 奇男,偶女

        return (Integer.parseInt(idno.substring(16, 17)) % 2) == 0 ? "1" : "0";

    }

 

    /**

     * 方法调用测试

     * */

    public static void main(String[] args) {

        String idc= "130503670401001";

        //检查身份证是否合规

        boolean idcard = isIdcard(idc);

        if (idcard) {

            System.out.println("身份证号码合规");

            // 获取身份证号码中的生日

            Date birthDay = getBirthDay(idc);

            System.out.println("当前身份证的生日为:"+ getBirthDayStr(idc));

            // 获取性别

            String gender = getGender(idc);

            if ("0".equals(gender)) {

                System.out.println("当前身份证的性别为:男性");

            } else if ("1".equals(gender)) {

                System.out.println("当前身份证的性别为:女性");

            } else {

                System.out.println("当前身份证格式不正确");

            }

        }else {

            System.out.println("身份证格式有误");

        }

    }

}

登入後複製

说明:以上工具中 main 方法是用于测试的,如果放入项目中,不能使用 main 方法测试,可以使用@Test 注解测试。此处用 main 方法,只是为了方便贴代码。

结果:

如何用JAVA驗證身分證號碼有效性

补充:java开发身份证号校验(边输入边校验)

公司最近有个需求,就是边输入边校验身份证号码是否合规。以往的校验都是输完够18位就校验,做起来简单的很,头一次听说要求这样搞的,搞了我一下午。

#代码利用多个正则表达式去校验字符

#判断年月日校验

#大小月校验

#闰年闰月的校验

####以下就是代码部分

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

/**

 * 功能:身份证的有效验证

 * @param idStr 身份证号

 * @return true 有效:false 无效

 */

public static boolean idCardValidate(String idStr) {

 

    try {

        int index = 1;

        //第一位不能为0

        if (idStr.length() >= index && idStr.indexOf("0") == 0) {

            return false;

        }

        //地区码

        index++;

        if (idStr.length() >= index) {

            Hashtable h = GetAreaCode();

            if (h.get(idStr.substring(0, index)) == null) {

                //errorInfo = "身份证地区编码错误。";

                return false;

            }

        }

        // 年份

        index = 6;

        //第一位只能是1和2

        if (!verify(idStr, index, "[1,2]")) {

            return false;

        }

        index++;

        //第二位跟随第一位只有9或0

        if (!verify(idStr, index,idStr.length()>index && idStr.substring(6,7).equals("1")?"[9]":"[0]")) {

            return false;

        }

        index++;

        //第三位 千禧年后0-?,千禧年前0-9

        if (!verify(idStr, index,idStr.length()>index &&  idStr.substring(6,7).equals("1")?"[0-9]":"[0-2]")) {

            return false;

        }

        index++;

        //第三位 0-9

        if (!verify(idStr, index, "[0-9]")) {

            return false;

        }

        if (idStr.length() > index) {

            //是否比当前年份大

            SimpleDateFormat ydf = new SimpleDateFormat("yyyy");

            if (ydf.parse(idStr.substring(6, 10)).getTime() > new Date().getTime()) {

                return false;

            }

        }

        // 月份

        index++;

        //第一位只能是1和0

        if (!verify(idStr, index, "[0,1]")) {

            return false;

        }

        index++;

        //第二位跟随第一位变化

        if (!verify(idStr, index, idStr.length()>index &&  idStr.substring(index-1,index).equals("1")?"[0-2]":"[1-9]")) {

            return false;

        }

        if (idStr.length() > index) {

            //是否比当前月份大

            SimpleDateFormat ydf = new SimpleDateFormat("yyyyMM");

            if (ydf.parse(idStr.substring(6, 12)).getTime() > new Date().getTime() && verifyMonth(idStr.substring(10, 12))) {

                return false;

            }

        }

        // ================ 日份 ================

        index++;

        //第一位 二月最多是2

        if (!verify(idStr, index,  idStr.length()>index &&  (dayMonth(idStr.substring(10, 12)) == 2)?"[0-2]":"[0-3]")) {

            return false;

        }

        index++;

        if (idStr.length()>index) {

            int ten = Integer.parseInt(idStr.substring(index-1, index));//上一位

            String filter = "[0-9]";

            switch (dayMonth(idStr.substring(10, 12))){

                case 1://31天

                    if(ten == 3){

                        filter = "[0,1]";

                    }

                    break;

                case 2://2月

                    if(ten == 2){

                        filter = "[0-8]";

                        int year = Integer.parseInt(idStr.substring(6, 10));

                        //闰年

                        if(year%400 == 0 || year%4==0){

                            filter = "[0-9]";

                        }

                    }

                    break;

                case 3://30天

                    if(ten == 3){

                        filter = "[0]";

                    }

                    break;

            }

            if(ten == 0){

                filter = "[1-9]";

            }

            if(!verifyIndex(idStr,index,filter)){

                return false;

            }

        }

        if (idStr.length() > index) {

            SimpleDateFormat ydf = new SimpleDateFormat("yyyyMMdd");

            //是否比当前日期大

            if (ydf.parse(idStr.substring(6, 14)).getTime() > new Date().getTime()) {

                return false;

            }

        }

        // 号码的长度

        String filter = "[0-9]{0,17}";

        boolean flag = idStr.matches(filter + (idStr.length() == 18 ? "[0-9,x,X]" : ""));

        if (!flag) {

            return false;

        }

    } catch (ParseException e) {

        e.printStackTrace();

        return false;

    }

    return true;

}

 

/**

 *  验证

 * @param text      文本

 * @param index     下标

 * @param filter    正则匹配

 * @return

 */

private static boolean verify(String text, int index, String filter) {

    //是否满足长度

    if (text.length() > index) {

        return verifyIndex(text, index, filter);

    }

    return true;

}

 

/**

 *  验证

 * @param text      文本

 * @param index     下标

 * @param filter    正则匹配

 * @return

 */

private static boolean verifyIndex(String text, int index, String filter) {

    String sub = text.substring(index, index + 1);

    return sub.matches(filter);

}

 

private static boolean verifyMonth(String month){

    return Integer.parseInt(month)>12;

}

 

/**

 *  大小月、二月

 * @return

 */

private static int dayMonth(String month){

    switch (Integer.parseInt(month)){

        case 4:

        case 6:

        case 9:

        case 11:

            return 3;

        case 2:return 2;

        default: return 1;

    }

}

 

/**

 * 功能:设置地区编码

 * @return Hashtable 对象

 */

private static Hashtable GetAreaCode() {

    Hashtable hashtable = new Hashtable();

    hashtable.put("11", "北京");

    hashtable.put("12", "天津");

    hashtable.put("13", "河北");

    hashtable.put("14", "山西");

    hashtable.put("15", "内蒙古");

    hashtable.put("21", "辽宁");

    hashtable.put("22", "吉林");

    hashtable.put("23", "黑龙江");

    hashtable.put("31", "上海");

    hashtable.put("32", "江苏");

    hashtable.put("33", "浙江");

    hashtable.put("34", "安徽");

    hashtable.put("35", "福建");

    hashtable.put("36", "江西");

    hashtable.put("37", "山东");

    hashtable.put("41", "河南");

    hashtable.put("42", "湖北");

    hashtable.put("43", "湖南");

    hashtable.put("44", "广东");

    hashtable.put("45", "广西");

    hashtable.put("46", "海南");

    hashtable.put("50", "重庆");

    hashtable.put("51", "四川");

    hashtable.put("52", "贵州");

    hashtable.put("53", "云南");

    hashtable.put("54", "西藏");

    hashtable.put("61", "陕西");

    hashtable.put("62", "甘肃");

    hashtable.put("63", "青海");

    hashtable.put("64", "宁夏");

    hashtable.put("65", "新疆");

    hashtable.put("71", "台湾");

    hashtable.put("81", "香港");

    hashtable.put("82", "澳门");

    hashtable.put("91", "国外");

    return hashtable;

}

登入後複製

以上是如何用JAVA驗證身分證號碼有效性的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱門文章

兩個點博物館:邦格荒地地點指南
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱門文章

兩個點博物館:邦格荒地地點指南
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱門文章標籤

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

Java 中的平方根 Java 中的平方根 Aug 30, 2024 pm 04:26 PM

Java 中的平方根

Java 中的完美數 Java 中的完美數 Aug 30, 2024 pm 04:28 PM

Java 中的完美數

Java 中的隨機數產生器 Java 中的隨機數產生器 Aug 30, 2024 pm 04:27 PM

Java 中的隨機數產生器

Java 中的阿姆斯壯數 Java 中的阿姆斯壯數 Aug 30, 2024 pm 04:26 PM

Java 中的阿姆斯壯數

Java中的Weka Java中的Weka Aug 30, 2024 pm 04:28 PM

Java中的Weka

Java Spring 面試題 Java Spring 面試題 Aug 30, 2024 pm 04:29 PM

Java Spring 面試題

突破或從Java 8流返回? 突破或從Java 8流返回? Feb 07, 2025 pm 12:09 PM

突破或從Java 8流返回?

Java 中的史密斯數 Java 中的史密斯數 Aug 30, 2024 pm 04:28 PM

Java 中的史密斯數

See all articles