private void requiredName_Validating(object sender, CancelEventArgs e) { string textInput = requiredName.Text.TrimStart().TrimEnd(); if (string.IsNullOrEmpty(textInput)) { MessageBox.Show("No name has been entered", "Salary Slip Application", MessageBoxButtons.OK, MessageBoxIcon.Error); requiredName.Focus(); } else if (!(RegularExpressionValidator.IsValidName(textInput))) { MessageBox.Show("The entered name is not in proper format", "Salary Slip Application", MessageBoxButtons.OK, MessageBoxIcon.Error); requiredName.Focus(); } }