mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
df9e71a596
commit
5c1ffbcc0c
@ -615,12 +615,18 @@ public class Validator {
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证是否为可用邮箱地址
|
||||
* 验证是否为可用邮箱地址<br>
|
||||
* 邮箱地址限制长度为254个字符,参考:https://stackoverflow.com/questions/386294/what-is-the-maximum-length-of-a-valid-email-address/44317754
|
||||
*
|
||||
* @param value 值
|
||||
* @return true为可用邮箱地址
|
||||
*/
|
||||
public static boolean isEmail(final CharSequence value) {
|
||||
final int codeLength = StrUtil.codeLength(value);
|
||||
if(codeLength < 1 || codeLength > 254){
|
||||
return false;
|
||||
}
|
||||
|
||||
return isMatchRegex(PatternPool.EMAIL, value);
|
||||
}
|
||||
|
||||
|
@ -61,9 +61,12 @@ public class PatternPool {
|
||||
*/
|
||||
public final static Pattern MONEY = Pattern.compile(RegexPool.MONEY);
|
||||
/**
|
||||
* 邮件,符合RFC 5322规范,正则来自:<a href="http://emailregex.com/">http://emailregex.com/</a><br>
|
||||
* <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.cn、jetz-chong@ hutool.cn、jetz_chong@hutool.cn、dazhi.duan@hutool.cn 宽松一点把,都算是正常的邮箱
|
||||
* 邮件,符合RFC 5322规范,注意email 要宽松一点。比如 jetz.chong@hutool.cn、jetz-chong@ hutool.cn、jetz_chong@hutool.cn、dazhi.duan@hutool.cn 宽松一点把,都算是正常的邮箱。
|
||||
* 参考:
|
||||
* <ul>
|
||||
* <li>https://stackoverflow.com/questions/386294/what-is-the-maximum-length-of-a-valid-email-address/44317754</li>
|
||||
* <li>https://stackoverflow.com/questions/201323/how-can-i-validate-an-email-address-using-a-regular-expression</li>
|
||||
* </ul>
|
||||
*/
|
||||
public final static Pattern EMAIL = Pattern.compile(RegexPool.EMAIL, Pattern.CASE_INSENSITIVE);
|
||||
/**
|
||||
|
@ -59,9 +59,13 @@ public interface RegexPool {
|
||||
*/
|
||||
String MONEY = "^(\\d+(?:\\.\\d+)?)$";
|
||||
/**
|
||||
* 邮件,符合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.cn、jetz-chong@ hutool.cn、jetz_chong@hutool.cn、dazhi.duan@hutool.cn 宽松一点把,都算是正常的邮箱
|
||||
* 邮件,符合RFC 5322规范,注意email 要宽松一点。比如 jetz.chong@hutool.cn、jetz-chong@ hutool.cn、jetz_chong@hutool.cn、dazhi.duan@hutool.cn 宽松一点把,都算是正常的邮箱。<br>
|
||||
* 正则来自:<a href="http://emailregex.com/">http://emailregex.com/</a>
|
||||
* 参考:
|
||||
* <ul>
|
||||
* <li>https://stackoverflow.com/questions/386294/what-is-the-maximum-length-of-a-valid-email-address/44317754</li>
|
||||
* <li>https://stackoverflow.com/questions/201323/how-can-i-validate-an-email-address-using-a-regular-expression</li>
|
||||
* </ul>
|
||||
*/
|
||||
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])+)])";
|
||||
/**
|
||||
|
@ -135,6 +135,12 @@ public class ValidatorTest {
|
||||
Assertions.assertTrue(email5);
|
||||
}
|
||||
|
||||
@Test
|
||||
void issueI94YYUTest() {
|
||||
final boolean ret = PatternPool.EMAIL.matcher(StrUtil.repeat("hutool\\\"", 1000)).matches();
|
||||
Assertions.assertFalse(ret);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isMobileTest() {
|
||||
final boolean m1 = Validator.isMobile("13900221432");
|
||||
@ -143,6 +149,8 @@ public class ValidatorTest {
|
||||
Assertions.assertTrue(m2);
|
||||
final boolean m3 = Validator.isMobile("+8618600221432");
|
||||
Assertions.assertTrue(m3);
|
||||
final boolean m4 = Validator.isMobile("19312341234");
|
||||
Assertions.assertTrue(m4);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user