/// <summary> /// This event handles the validation of a addition or deduction rule entered by a user in the (name,value) format. /// </summary> /// <param name="sender">The control that fired the event.</param> /// <param name="e">Event arguments.</param> private void validateRuleName_Validation(object sender, CancelEventArgs e) { TextBox senderControl = (TextBox)sender; string textBoxInput = senderControl.Text.TrimStart(' ').TrimEnd(' '); //check line for first if case. if (string.IsNullOrEmpty(textBoxInput)) { MessageBox.Show(string.Format("No value entered for text box {0}", senderControl.Name), "Salary Slip Application", MessageBoxButtons.OK, MessageBoxIcon.Error); senderControl.Focus(); } else if (!(RegularExpressionValidator.IsValidComponentValuePair(textBoxInput))) { MessageBox.Show(string.Format("The Name,Value pair {0} of textbox {1} is not in proper format", senderControl.Text, senderControl.Name), "Salary Slip Application", MessageBoxButtons.OK, MessageBoxIcon.Error); senderControl.Focus(); } }