0

Below is the code for inserting data via input boxes into my table, I have used some data validation already but want to know how to verify that an email address input box is in email format (@ .)

    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();
Oliver Hanappi
  • 12,046
  • 7
  • 51
  • 68
Aaron G
  • 7
  • 4
  • 8
    Possible duplicate of [C# code to validate email address](http://stackoverflow.com/questions/1365407/c-sharp-code-to-validate-email-address) – NotTelling Mar 17 '17 at 10:07
  • check [this](http://stackoverflow.com/questions/7173401/c-sharp-email-validation-confused-by-mailaddress-behavior-johngmail-is-val) question maybe it helps – jelle woord Mar 17 '17 at 10:11
  • Hi Instanfin, thanks for your help I had read that question but don't really understand what was being written, and was looking for someone to explain it to me if possible rather than me copying. – Aaron G Mar 17 '17 at 12:32

1 Answers1

-1

You can check the link below.. I think it is one of the awesome way to validate email.. Using try..catch block to get the boolean.. https://stackoverflow.com/a/1374644/5518217

Community
  • 1
  • 1
WinMaker
  • 59
  • 5