邮箱校验添加对中文的支持

This commit is contained in:
Looly 2023-05-14 23:18:28 +08:00
parent 9c532f8a15
commit 7894e58171
3 changed files with 7 additions and 5 deletions

View File

@ -59,11 +59,11 @@ public interface RegexPool {
*/
String MONEY = "^(\\d+(?:\\.\\d+)?)$";
/**
* 邮件符合RFC 5322规范正则来自<a href="http://emailregex.com/">http://emailregex.com/</a>
* 邮件符合RFC 5322规范
* What is the maximum length of a valid email address? <a href="https://stackoverflow.com/questions/386294/what-is-the-maximum-length-of-a-valid-email-address/44317754">https://stackoverflow.com/questions/386294/what-is-the-maximum-length-of-a-valid-email-address/44317754</a>
* 注意email 要宽松一点比如 jetz.chong@hutool.cnjetz-chong@ hutool.cnjetz_chong@hutool.cndazhi.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])+)])";
String EMAIL = "(?:[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])+)])";
/**
* 移动电话<br>
* eg: 中国大陆 +86 180 4953 13992位区域码标示+13位数字

View File

@ -121,6 +121,8 @@ public class ValidatorTest {
Assertions.assertTrue(email3);
final boolean email4 = Validator.isEmail("xiaolei.Lu@aaa.b");
Assertions.assertTrue(email4);
final boolean email5 = Validator.isEmail("luxiaolei_小磊@小磊.com");
Assertions.assertTrue(email5);
}
@Test

View File

@ -31,10 +31,10 @@ import java.util.Map;
import java.util.Map.Entry;
/**
* 邮件工具类基于javax.mail封装
* 邮件工具类基于jakarta.mail封装
*
* @author looly
* @since 3.1.2
* @since 6.0.0
*/
public class MailUtil {
/**
@ -387,7 +387,7 @@ public class MailUtil {
}
return isSingleton ? Session.getDefaultInstance(mailAccount.getSmtpProps(), authenticator) //
: Session.getInstance(mailAccount.getSmtpProps(), authenticator);
: Session.getInstance(mailAccount.getSmtpProps(), authenticator);
}
// ------------------------------------------------------------------------------------------------------------------------ Private method start