【新增】封装账号类型校验工具
This commit is contained in:
35
src/main/java/com/corewing/app/util/AccountUtil.java
Normal file
35
src/main/java/com/corewing/app/util/AccountUtil.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.corewing.app.util;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class AccountUtil {
|
||||
|
||||
/**
|
||||
* 手机号正则
|
||||
*/
|
||||
private static final Pattern PHONE_PATTERN = Pattern.compile("^1[3-9]\\d{9}$");
|
||||
|
||||
/**
|
||||
* 邮箱正则
|
||||
*/
|
||||
private static final Pattern EMAIL_PATTERN = Pattern.compile("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$");
|
||||
|
||||
/**
|
||||
* 校验是否是手机号
|
||||
* @param email
|
||||
* @return
|
||||
*/
|
||||
public static boolean isEmail(String email) {
|
||||
return EMAIL_PATTERN.matcher(email).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验是否是手机
|
||||
* @param phoneNumber
|
||||
* @return
|
||||
*/
|
||||
public static boolean isPhone(String phoneNumber) {
|
||||
return PHONE_PATTERN.matcher(phoneNumber).matches();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user