Android 郵箱驗證

boolean checkUserName(EditText editText) {
       String userName = editText.getText().toString().trim();
       errrToast(userName);
       /*
        * 正則表達式 測試 郵箱是否合法
        */
       Pattern pattern = Pattern.compile(
               "[\\w\\.\\-]+@([\\w\\-]+\\.)+[\\w\\-]+",
               Pattern.CASE_INSENSITIVE);
       Matcher matcher = pattern.matcher(userName);
       if (matcher.matches()) {
           return true;
       }
       errrToast("郵箱格式輸入錯誤");
       return false;
   }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章