正则验证邮箱格式是不是正确

前端之家收集整理的这篇文章主要介绍了正则验证邮箱格式是不是正确前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. <span style="font-size:14px;">验证该邮箱格式是不是正确</span>
  1. <span style="font-size:14px;">public class StringDemo1 {
  2. public static void main(String[] args) {
  3. /*
  4. * 邮箱的正则表达式
  5. *
  6. * [a-zA-Z0-9_]+@[a-zA-Z0-9_]+(\.[a-zA-Z]+)+
  7. */
  8. /*
  9. * String类中提供了一个方法,可以用给定
  10. * 的正则表达式来验证当前字符串的格式是否
  11. * 满足要求
  12. * boolean matches(String regex)
  13. */
  14. String email
  15. = "cwj@163.cn";
  16. String regex
  17. = "[a-zA-Z0-9_]+@[a-zA-Z0-9_]+(\\.[a-zA-Z]+)+";
  18. boolean cwj1=email.matches(regex);
  19. if (cwj1) {
  20. System.out.println("是邮箱!");
  21. }else {
  22. System.out.println("不是邮箱!");
  23. }
  24. }
  25. }</span>

猜你在找的正则表达式相关文章