1
我有一個Windows窗體應用程序,我被命名爲textbox1
的文本框,我希望用戶只能輸入像這樣的電子郵件:[email protected]
。不是一些隨機文本或隨機數字。如何驗證文本框上的正確電子郵件地址
我有一個Windows窗體應用程序,我被命名爲textbox1
的文本框,我希望用戶只能輸入像這樣的電子郵件:[email protected]
。不是一些隨機文本或隨機數字。如何驗證文本框上的正確電子郵件地址
使用正則表達式爲:)
private void txtEmail_Leave(object sender, EventArgs e)
{
Regex mRegxExpression;
if (txtEmail.Text.Trim() != string.Empty)
{
mRegxExpression = new Regex(@"^([a-zA-Z0-9_\-])([a-zA-Z0-9_\-\.]*)@(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])$");
if (!mRegxExpression.IsMatch(txtEmail.Text.Trim()))
{
MessageBox.Show("E-mail address format is not correct.", "MojoCRM", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtEmail.Focus();
}
}
}
下面我想,你真的需要閱讀本http://stackoverflow.com/questions/5342375/c-sharp-regex-email-validation – Steve