mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
commit
721faf353a
@ -54,6 +54,11 @@ public class PatternPool {
|
||||
* 注意email 要宽松一点。比如 jetz.chong@hutool.cn、jetz-chong@ hutool.cn、jetz_chong@hutool.cn、dazhi.duan@hutool.cn 宽松一点把,都算是正常的邮箱
|
||||
*/
|
||||
public final static Pattern EMAIL = Pattern.compile(RegexPool.EMAIL, Pattern.CASE_INSENSITIVE);
|
||||
|
||||
/**
|
||||
* 规则同EMAIL,添加了对中文的支持
|
||||
*/
|
||||
public final static Pattern EMAIL_WITH_CHINESE = Pattern.compile(RegexPool.EMAIL_WITH_CHINESE,Pattern.CASE_INSENSITIVE);
|
||||
/**
|
||||
* 移动电话
|
||||
*/
|
||||
|
@ -52,6 +52,11 @@ public interface RegexPool {
|
||||
* 注意email 要宽松一点。比如 jetz.chong@hutool.cn、jetz-chong@ hutool.cn、jetz_chong@hutool.cn、dazhi.duan@hutool.cn 宽松一点把,都算是正常的邮箱
|
||||
*/
|
||||
String EMAIL = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)])";
|
||||
|
||||
/**
|
||||
* 规则同EMAIL,添加了对中文的支持
|
||||
*/
|
||||
String EMAIL_WITH_CHINESE = "(?:[a-z0-9\\u4e00-\\u9fa5!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9\\u4e00-\\u9fa5!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9\\u4e00-\\u9fa5](?:[a-z0-9\\u4e00-\\u9fa5-]*[a-z0-9\\u4e00-\\u9fa5])?\\.)+[a-z0-9\\u4e00-\\u9fa5](?:[a-z0-9\\u4e00-\\u9fa5-]*[a-z0-9\\u4e00-\\u9fa5])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9\\u4e00-\\u9fa5-]*[a-z0-9\\u4e00-\\u9fa5]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)])";
|
||||
/**
|
||||
* 移动电话
|
||||
* eg: 中国大陆: +86 180 4953 1399,2位区域码标示+11位数字
|
||||
|
@ -55,6 +55,12 @@ public class Validator {
|
||||
* 邮件
|
||||
*/
|
||||
public final static Pattern EMAIL = PatternPool.EMAIL;
|
||||
|
||||
/**
|
||||
* 邮件(包含中文)
|
||||
*/
|
||||
public final static Pattern EMAIL_WITH_CHINESE = PatternPool.EMAIL_WITH_CHINESE;
|
||||
|
||||
/**
|
||||
* 移动电话
|
||||
*/
|
||||
@ -684,6 +690,21 @@ public class Validator {
|
||||
return isMatchRegex(EMAIL, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证是否为可用邮箱地址(兼容中文邮箱地址)
|
||||
*
|
||||
* @param value 值
|
||||
* @param includChinese 包含中文标识
|
||||
* @return true为可用邮箱地址
|
||||
*/
|
||||
public static boolean isEmail(CharSequence value,boolean includChinese) {
|
||||
if (includChinese){
|
||||
return isMatchRegex(EMAIL_WITH_CHINESE, value);
|
||||
}
|
||||
return isEmail(value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 验证是否为可用邮箱地址
|
||||
*
|
||||
|
@ -113,6 +113,8 @@ public class ValidatorTest {
|
||||
Assert.assertTrue(email3);
|
||||
boolean email4 = Validator.isEmail("xiaolei.Lu@aaa.b");
|
||||
Assert.assertTrue(email4);
|
||||
boolean email5 = Validator.isEmail("luxiaolei_路小磊@路小磊.com",true);
|
||||
Assert.assertTrue(email5);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user