Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
head_group
xyqb-user2
Commits
6726bf85
Commit
6726bf85
authored
Jul 13, 2020
by
董建华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加去掉首尾汉字的正则
parent
f7694f9f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
0 deletions
+12
-0
AddressFilter.java
src/main/java/cn/quantgroup/xyqb/util/AddressFilter.java
+12
-0
No files found.
src/main/java/cn/quantgroup/xyqb/util/AddressFilter.java
View file @
6726bf85
...
@@ -36,6 +36,9 @@ public class AddressFilter {
...
@@ -36,6 +36,9 @@ public class AddressFilter {
//邮箱正则
//邮箱正则
private
static
Pattern
EMAIL_PATTERN
=
Pattern
.
compile
(
"^[A-Za-z0-9]+([._\\-]*[A-Za-z0-9])*@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$"
);
private
static
Pattern
EMAIL_PATTERN
=
Pattern
.
compile
(
"^[A-Za-z0-9]+([._\\-]*[A-Za-z0-9])*@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$"
);
//首尾中文
private
static
Pattern
CHINA_PATTERN
=
Pattern
.
compile
(
"^[\u4e00-\u9fa5]+|[\u4e00-\u9fa5]+$"
);
static
{
static
{
synchronized
(
AddressFilter
.
class
)
{
synchronized
(
AddressFilter
.
class
)
{
if
(
PATTERN_LIST
.
size
()
==
0
)
{
if
(
PATTERN_LIST
.
size
()
==
0
)
{
...
@@ -96,6 +99,10 @@ public class AddressFilter {
...
@@ -96,6 +99,10 @@ public class AddressFilter {
//去掉所有的空白
//去掉所有的空白
if
(
null
!=
email
){
if
(
null
!=
email
){
email
=
email
.
replaceAll
(
"\\s"
,
""
);
email
=
email
.
replaceAll
(
"\\s"
,
""
);
Matcher
matcher
=
CHINA_PATTERN
.
matcher
(
email
);
if
(
matcher
.
find
()){
email
=
matcher
.
replaceAll
(
""
);
}
}
}
if
(
isEmail
(
email
)){
if
(
isEmail
(
email
)){
...
@@ -121,6 +128,7 @@ public class AddressFilter {
...
@@ -121,6 +128,7 @@ public class AddressFilter {
Matcher
matcher
=
EMAIL_PATTERN
.
matcher
(
email
);
Matcher
matcher
=
EMAIL_PATTERN
.
matcher
(
email
);
return
matcher
.
matches
();
return
matcher
.
matches
();
}
}
@Getter
@Getter
@Setter
@Setter
@AllArgsConstructor
@AllArgsConstructor
...
@@ -129,4 +137,8 @@ public class AddressFilter {
...
@@ -129,4 +137,8 @@ public class AddressFilter {
private
String
replaceMent
;
private
String
replaceMent
;
}
}
public
static
void
main
(
String
[]
args
)
{
String
email
=
getEmail
(
"18518759303"
,
"啊412763575@qq.com董建华"
);
System
.
out
.
println
(
email
);
}
}
}
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