protected void Button1_Click(object sender, EventArgs e) { DateTime currentDate; currentDate = DateTime.Now; DateLabel.Text = currentDate.ToShortDateString(); DateTime currentTime; currentTime = DateTime.Now; TimeLabel.Text = currentTime.ToShortTimeString(); OutputLabel.Text = string.Empty; if (FirstNameTextBox.Text == string.Empty) { OutputLabel.Text = "Must enter a first name"; FirstNameTextBox.Focus(); return; } if (LastNameTextBox.Text == string.Empty) { OutputLabel.Text = "Must enter a last name"; LastNameTextBox.Focus(); return; } if (AreaCodeTextBox.Text == string.Empty) { OutputLabel.Text = "Must enter an area code"; AreaCodeTextBox.Focus(); return; } if (AreaCodeTextBox.Text.Length < 3) { OutputLabel.Text = "Area code must be 3 digits"; AreaCodeTextBox.Text = string.Empty; AreaCodeTextBox.Focus(); return; } Int32 AreaCodeEnterednumber; if (!Int32.TryParse(AreaCodeTextBox.Text, out AreaCodeEnterednumber)) { OutputLabel.Text = "Area code must be 3 digits"; AreaCodeTextBox.Text = string.Empty; return; } if (ExchangeTextBox.Text == string.Empty) { OutputLabel.Text = "Must enter an exchange"; ExchangeTextBox.Focus(); return; } if (ExchangeTextBox.Text.Length < 3) { OutputLabel.Text = "Exchange must be 3 digits"; ExchangeTextBox.Text = string.Empty; ExchangeTextBox.Focus(); return; } Int32 ExchangeEnterednumber; if (!Int32.TryParse(ExchangeTextBox.Text, out ExchangeEnterednumber)) { OutputLabel.Text = "Exchange must be 3 digits"; ExchangeTextBox.Text = string.Empty; ExchangeTextBox.Focus(); return; } if (NumberTextBox.Text == string.Empty) { OutputLabel.Text = "Must enter number"; NumberTextBox.Focus(); return; } if (NumberTextBox.Text.Length < 4) { OutputLabel.Text = "Number must be 4 digits"; NumberTextBox.Text = string.Empty; NumberTextBox.Focus(); return; } Int32 NumberEnterednumber; if (!Int32.TryParse(NumberTextBox.Text, out NumberEnterednumber)) { OutputLabel.Text = "Number must be 4 digits"; NumberTextBox.Text = string.Empty; NumberTextBox.Focus(); return; } if (EmailTextBox.Text.Length < 5) { OutputLabel.Text = "Must be at least 5 characters"; return; } if (!EmailTextBox.Text.Contains("@")) { OutputLabel.Text = "Must contain @"; return; } if (EmailTextBox.Text.Substring(0, 1) == "@" || EmailTextBox.Text.Substring(EmailTextBox.Text.Length - 2, 1) == "@" || EmailTextBox.Text.Substring(EmailTextBox.Text.Length - 1, 1) == "@") { OutputLabel.Text = "@ Character may not be the 1st character nor one of the last 2"; return; } if (EmailTextBox.Text.Substring(2, 1) == "." || EmailTextBox.Text.Substring(EmailTextBox.Text.Length - 1, 1) == ".") { } }
private void ForceValidation() { AreaCodeTextBox.GetBindingExpression(TextBox.TextProperty).ValidateWithoutUpdate(); AreaNameTextBox.GetBindingExpression(TextBox.TextProperty).ValidateWithoutUpdate(); }