什么是最好的Java电子邮件地址验证方法?Java的电子邮件地址验证库是什么?除了公域验证器?
3 回答
潇湘沐
TA贡献1816条经验 获得超6个赞
public static boolean isValidEmailAddress(String email) { boolean result = true; try { InternetAddress emailAddr = new InternetAddress(email); emailAddr.validate(); } catch (AddressException ex) { result = false; } return result;}
慕少森
TA贡献2019条经验 获得超9个赞
<dependency> <groupId>commons-validator</groupId> <artifactId>commons-validator</artifactId> <version>1.4.1</version></dependency>
compile 'commons-validator:commons-validator:1.4.1'
import org.apache.commons.validator.routines.EmailValidator;
String email = "myName@example.com";boolean valid = EmailValidator.getInstance().isValid(email);
boolean allowLocal = true;boolean valid = EmailValidator.getInstance(allowLocal).isValid(email);
添加回答
举报
0/150
提交
取消