Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
0d046be0
Commit
0d046be0
authored
Jan 23, 2024
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
身份证识别
parent
7c784fb4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
21 deletions
+49
-21
SfzHandle18.java
...e/src/main/java/com/yanzuoguang/util/sfz/SfzHandle18.java
+27
-15
SfzHandleEn2023.java
...c/main/java/com/yanzuoguang/util/sfz/SfzHandleEn2023.java
+22
-6
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/sfz/SfzHandle18.java
View file @
0d046be0
...
@@ -24,22 +24,34 @@ public class SfzHandle18 implements SfzHandle {
...
@@ -24,22 +24,34 @@ public class SfzHandle18 implements SfzHandle {
@Override
@Override
public
boolean
validate
(
String
idCard
)
{
public
boolean
validate
(
String
idCard
)
{
if
(
idCard
.
length
()
==
CHINA_ID_MAX_LENGTH
&&
!
idCard
.
startsWith
(
SfzHandleEn2023
.
START
))
{
return
validate18
(
idCard
);
}
return
false
;
}
/**
* 验证身份证校验是否合法
*
* @param idCard 身份证
* @return 校验合法
*/
public
static
boolean
validate18
(
String
idCard
)
{
boolean
bTrue
=
false
;
boolean
bTrue
=
false
;
if
(
idCard
.
length
()
==
CHINA_ID_MAX_LENGTH
)
{
int
endIndex
=
idCard
.
length
()
-
1
;
// 前17位
// 前17位
String
code17
=
idCard
.
substring
(
0
,
17
);
String
code17
=
idCard
.
substring
(
0
,
endIndex
);
// 第18位
// 第18位
String
code18
=
idCard
.
substring
(
17
,
CHINA_ID_MAX_LENGTH
);
String
code18
=
idCard
.
substring
(
endIndex
);
if
(
SfzHandleUtil
.
isNum
(
code17
))
{
if
(
SfzHandleUtil
.
isNum
(
code17
))
{
char
[]
cArr
=
code17
.
toCharArray
();
char
[]
cArr
=
code17
.
toCharArray
();
if
(
cArr
!=
null
)
{
if
(
cArr
!=
null
)
{
int
[]
iCard
=
converCharToInt
(
cArr
);
int
[]
iCard
=
converCharToInt
(
cArr
);
int
iSum17
=
getPowerSum
(
iCard
);
int
iSum17
=
getPowerSum
(
iCard
);
// 获取校验位
// 获取校验位
String
val
=
getCheckCode18
(
iSum17
);
String
val
=
getCheckCode18
(
iSum17
);
if
(
val
.
length
()
>
0
&&
val
.
equalsIgnoreCase
(
code18
))
{
if
(
val
.
length
()
>
0
&&
val
.
equalsIgnoreCase
(
code18
))
{
bTrue
=
true
;
bTrue
=
true
;
}
}
}
}
}
}
}
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/sfz/SfzHandleEn2023.java
View file @
0d046be0
package
com
.
yanzuoguang
.
util
.
sfz
;
package
com
.
yanzuoguang
.
util
.
sfz
;
import
static
com
.
yanzuoguang
.
util
.
sfz
.
SfzHandle15
.
CHINA_ID_MIN_LENGTH
;
import
static
com
.
yanzuoguang
.
util
.
sfz
.
SfzHandle18
.
CHINA_ID_MAX_LENGTH
;
import
static
com
.
yanzuoguang
.
util
.
sfz
.
SfzHandleUtil
.
cityCodes
;
/**
/**
* 2023年国外永居证处理
* 2023年国外永居证处理
*
*
* @author 颜佐光
* @author 颜佐光
*/
*/
public
class
SfzHandleEn2023
implements
SfzHandle
{
public
class
SfzHandleEn2023
implements
SfzHandle
{
public
static
final
String
START
=
"9"
;
@Override
@Override
public
boolean
validate
(
String
idCard
)
{
public
boolean
validate
(
String
idCard
)
{
if
(
idCard
.
length
()
==
CHINA_ID_MAX_LENGTH
&&
idCard
.
startsWith
(
SfzHandleEn2023
.
START
))
{
return
SfzHandle18
.
validate18
(
idCard
);
}
return
false
;
return
false
;
}
}
@Override
@Override
public
String
repair
(
String
idCard
)
{
public
String
repair
(
String
idCard
)
{
return
null
;
return
idCard
;
}
}
@Override
@Override
public
String
getGender
(
String
idCard
)
{
public
String
getGender
(
String
idCard
)
{
return
null
;
return
SfzHandleUtil
.
SFZ_HANDLE_18
.
getGender
(
idCard
)
;
}
}
@Override
@Override
public
String
getBirthday
(
String
idCard
)
{
public
String
getBirthday
(
String
idCard
)
{
return
null
;
return
SfzHandleUtil
.
SFZ_HANDLE_18
.
getGender
(
idCard
)
;
}
}
@Override
@Override
public
String
getCountry
(
String
idCard
)
{
public
String
getCountry
(
String
idCard
)
{
return
null
;
return
idCard
.
substring
(
3
,
6
)
;
}
}
@Override
@Override
public
String
getAreaId
(
String
idCard
)
{
public
String
getAreaId
(
String
idCard
)
{
return
null
;
return
idCard
.
substring
(
1
,
3
)
;
}
}
@Override
@Override
public
String
getProvinceName
(
String
idCard
)
{
public
String
getProvinceName
(
String
idCard
)
{
return
null
;
int
len
=
idCard
.
length
();
String
sProvince
=
null
;
String
sProvinNum
=
""
;
if
(
len
==
CHINA_ID_MIN_LENGTH
||
len
==
CHINA_ID_MAX_LENGTH
)
{
sProvinNum
=
idCard
.
substring
(
1
,
3
);
}
sProvince
=
cityCodes
.
get
(
sProvinNum
);
return
sProvince
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment