0
下面是通過輸入框將數據插入到表中的代碼,我已經使用了一些數據驗證,但想知道如何驗證電子郵件地址輸入框是否在如何在C#中爲電子郵件地址創建數據驗證
private void ECVSavebutton(object sender, RoutedEventArgs e)
{
string EmployeeAvailability;
if (Job1DropDownBox.Text == "True" && Job2DropDownBox.Text == "True" && Job3DropDownBox.Text == "True")
{
EmployeeAvailability = "False";
} else
{
EmployeeAvailability = "True";
}
{
if (PostcodeInputBox.Text.Count() >= 7)
PostcodeInputBox.Text = null;
}
Connection.Open();
SqlCommand Command = new SqlCommand(null, Connection);
Command.CommandText = "Insert into [StaffDetails] (Forename,Surname,DateofBirth,Emailaddress,Country,Address,City,Postcode,Skill1,Skill2,Skill3,Job1,Job2,Job3,EmployeeAvailability,Location) Values(@forename, @surname, @dateofbirth, @emailaddress, @country, @address, @city, @postcode, @skill1, @skill2, @skill3, @job1, @job2, @job3, @employeeavailability,@location)";
Command.Parameters.AddWithValue("@forename", ForenameInputBox.Text);
Command.Parameters.AddWithValue("@surname", SurnameInputBox.Text);
Command.Parameters.AddWithValue("@dateofbirth", DateOfBirthPicker.SelectedDate);
Command.Parameters.AddWithValue("@emailaddress", EmailInputBox.Text);
Command.Parameters.AddWithValue("@country", CountryInputBox.Text);
Command.Parameters.AddWithValue("@address", AddressInputBox.Text);
Command.Parameters.AddWithValue("@city", CityInputBox.Text);
Command.Parameters.AddWithValue("@postcode", PostcodeInputBox.Text);
Command.Parameters.AddWithValue("@skill1", Skill1DropDownBox.Text);
Command.Parameters.AddWithValue("@skill2", Skill2DropDownBox.Text);
Command.Parameters.AddWithValue("@skill3", Skill3DropDownBox.Text);
Command.Parameters.AddWithValue("@job1", Job1DropDownBox.Text);
Command.Parameters.AddWithValue("@job2", Job2DropDownBox.Text);
Command.Parameters.AddWithValue("@job3", Job3DropDownBox.Text);
Command.Parameters.AddWithValue("@employeeavailability", EmployeeAvailability);
Command.Parameters.AddWithValue("@location", LocationDropDownBox.Text);
Command.ExecuteNonQuery();
Connection.Close();
[C#代碼驗證電子郵件地址]的可能重複(http://stackoverflow.com/questions/1365407/c-sharp-code-to-驗證電子郵件地址) – NotTelling
檢查[此](http://stackoverflow.com/questions/7173401/c-sharp-email-validation-confused-by-mailaddress-behavior-johngmail-is-val)問題也許它有幫助 –
嗨Instanfin,感謝您的幫助我已經閱讀過這個問題,但並不真正瞭解正在寫什麼,並且正在尋找某人向我解釋,如果可能的話,而不是我抄襲。 –