Java正則表達式校驗QQ號碼和郵箱地址格式


 1 public class Demo02 {
 2     public static void main(String[] args) {
 3         Scanner sc = new Scanner(System.in);
 4         String s = "";
 5         System.out.println("請輸入一個字符串");
 6         s = sc.nextLine();
 7         // System.out.println(checkQQ(s));            
 8         System.out.println(checkEmail(s));
 9     }
10     
11     // 利用正則表達式校驗QQ號
12     public static boolean checkQQ(String str) {
13         return str.matches("[1-9][0-9]{4,14}");    // matches()方法告知此字符串是否匹配給定的正則表達式。 
14     }
15     
16     // 校驗郵箱地址
17     public static boolean checkEmail(String email) {
18         return email.matches("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$");
19     }
20 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM