2012-06-25 34 views
0

我想把驗證器,以便如果用戶沒有以正確的格式,即[email protected]電子郵件ID,應該彈出一個錯誤消息。我如何將這個驗證器用於Windows Mobile?如何驗證文本框中的電子郵件格式?

+0

Windows mobile(每個問題)或Windows phone(每個標記)?畢竟這是兩個完全不同的移動平臺 –

回答

2
using System; 
using System.Text.RegularExpressions; 

    public static bool IsValidEmail(string strIn) 
     { 
      // Return true if strIn is in valid e-mail format. 
      return Regex.IsMatch(strIn, 
        @"^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))" + 
        @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$"); 
     } 
相關問題