java驗證手機號格式

/**
     * 手機號驗證
     * @param phoneNum
     * @return
     */
    
    public static boolean CheckMobilePhoneNum(String phoneNum) {
        String regex = "^(1[3-9]\\d{9}$)";
        if (phoneNum.length() == 11) {
             Pattern p = Pattern.compile(regex);
             Matcher m = p.matcher(phoneNum);
             if (m.matches()) {
                 return true;
             }
        }
        return false;
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章