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
Show 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,12 +24,25 @@ public class SfzHandle18 implements SfzHandle {
@Override
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
;
i
f
(
idCard
.
length
()
==
CHINA_ID_MAX_LENGTH
)
{
i
nt
endIndex
=
idCard
.
length
()
-
1
;
// 前17位
String
code17
=
idCard
.
substring
(
0
,
17
);
String
code17
=
idCard
.
substring
(
0
,
endIndex
);
// 第18位
String
code18
=
idCard
.
substring
(
17
,
CHINA_ID_MAX_LENGTH
);
String
code18
=
idCard
.
substring
(
endIndex
);
if
(
SfzHandleUtil
.
isNum
(
code17
))
{
char
[]
cArr
=
code17
.
toCharArray
();
if
(
cArr
!=
null
)
{
...
...
@@ -42,7 +55,6 @@ public class SfzHandle18 implements SfzHandle {
}
}
}
}
return
bTrue
;
}
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/sfz/SfzHandleEn2023.java
View file @
0d046be0
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年国外永居证处理
*
* @author 颜佐光
*/
public
class
SfzHandleEn2023
implements
SfzHandle
{
public
static
final
String
START
=
"9"
;
@Override
public
boolean
validate
(
String
idCard
)
{
if
(
idCard
.
length
()
==
CHINA_ID_MAX_LENGTH
&&
idCard
.
startsWith
(
SfzHandleEn2023
.
START
))
{
return
SfzHandle18
.
validate18
(
idCard
);
}
return
false
;
}
@Override
public
String
repair
(
String
idCard
)
{
return
null
;
return
idCard
;
}
@Override
public
String
getGender
(
String
idCard
)
{
return
null
;
return
SfzHandleUtil
.
SFZ_HANDLE_18
.
getGender
(
idCard
)
;
}
@Override
public
String
getBirthday
(
String
idCard
)
{
return
null
;
return
SfzHandleUtil
.
SFZ_HANDLE_18
.
getGender
(
idCard
)
;
}
@Override
public
String
getCountry
(
String
idCard
)
{
return
null
;
return
idCard
.
substring
(
3
,
6
)
;
}
@Override
public
String
getAreaId
(
String
idCard
)
{
return
null
;
return
idCard
.
substring
(
1
,
3
)
;
}
@Override
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