Blogtrottr
海芋小站
提供實用軟體教學,介紹有趣網站及資訊,豐富電腦人生 
Continuous Deployment Tool

Automate from SCM to Production with BuildMaster! 100+ Integrations; Free for 5 Users.
From our sponsors
[Android 開發] 如何檢查輸入的文字是否為 Email 格式?
Jun 13th 2014, 03:03, by 張海芋

在 Android 的開發上,我們通常會使用 EditText 來輸入文字,而如果今天我們有一個欄位需要使用者來填寫 Email,並且驗證使用者所填的資料是否正確,那麼該怎麼做呢?其實很簡單,只要下面兩個步驟,就可以驗證使用者輸入的文字是否為 Email 格式了。

首先,我們在 XML 中要先進行限制,讓使用者只能輸入 Email 格式所可以接受的字元。

1
2
3
4
<EditText
   android:id="@+id/edittext_email"
   android:singleLine="true"
   android:inputType="textEmailAddress" />

接下來,再於程式進行判斷即可。

1
2
3
4
5
6
7
private boolean isVaildEmailFormat()
{
    EditText etMail = (EditText)   findViewById(R.id.edittext_email);
    if (etMail == null)
        return false;
    return android.util.Patterns.EMAIL_ADDRESS.matcher(_edittext.getText().toString()).matches();
}
留言回應 或者 訂閱 RSS feed 以獲得更多的文章更新資訊。若有商業上的需求,也歡迎透過 合作提案 與我聯絡。本站文章非經授權請勿「全文轉貼」,引用時請註明來源,謝謝。

This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers.

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed, or manage all your subscriptions
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 kko2oj3x91bmh 的頭像
    kko2oj3x91bmh

    派遣女醫x線上看 派遣女醫x劇情 派遣女醫x第2部 派遣女醫x 線上 派遣女醫x 2 派遣女醫x 2線上看 派遣女醫x第二部 派遣女醫x第2部線上看

    kko2oj3x91bmh 發表在 痞客邦 留言(0) 人氣()