1. Java使用正则表达式检查Email地址的有效性
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import java.util.regex.Matcher; import java.util.regex.Pattern; private boolean isValidEmail(String email){ boolean isValid = false; Pattern p = Pattern.compile("w+@(w+.)+[a-z]{2,3}"); Matcher m = p.matcher(email); boolean b = m.matches(); if(b) { System.out.println("有效的邮件地址。"); isValid=true; } else { System.out.println("无效的邮件地址。"); } return isValid; } |