Android註冊功能--電話驗證和郵箱驗證

yangxi_001發表於2014-04-09

    // 電話驗證
    public static boolean phoneFormat(String phoneNumber){
        Pattern pattern = Pattern
                .compile("((^(13|15|18)[0-9]{9}$)|(^0[1,2]{1}\\d{1}-?\\d{8}$)|(^0[3-9] {1}\\d{2}-?\\d{7,8}$)|(^0[1,2]{1}\\d{1}-?\\d{8}-(\\d{1,4})$)|(^0[3-9]{1}\\d{2}-?\\d{7,8}-(\\d{1,4})$))");
        Matcher matcher = pattern.matcher(phoneNumber);
        return matcher.matches();
    }


    // 郵箱驗證
    public static boolean emailFormat(String email) {
        Pattern pattern = Pattern
                .compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
        Matcher mc = pattern.matcher(email);
        return mc.matches();
    }

相關文章