2015-10-22 41 views

回答

2

使用正則表達式爲:)

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();  
     }  
    }  
}