<span style="font-size:14px;">驗證該郵箱格式是不是正確</span>
<span style="font-size:14px;">public class StringDemo1 { public static void main(String[] args) { /* * 郵箱的正則表達式 * * [a-zA-Z0-9_]+@[a-zA-Z0-9_]+(\.[a-zA-Z]+)+ */ /* * String類中提供了一個方法,能夠用給定 * 的正則表達式來驗證當前字符串的格式是否 * 滿足要求 * boolean matches(String regex) */ String email = "cwj@163.cn"; String regex = "[a-zA-Z0-9_]+@[a-zA-Z0-9_]+(\\.[a-zA-Z]+)+"; boolean cwj1=email.matches(regex); if (cwj1) { System.out.println("是郵箱!"); }else { System.out.println("不是郵箱。"); } } }</span>