Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string invalidChars = ""; // List of invalid characters
- private void txtYear_TextChanged(object sender, EventArgs e)
- {
- Control ctr = (Control)sender;
- // Show error alert
- if (ctr.Text.Trim().Length > 0 && !char.IsDigit(ctr.Text, ctr.Text.Length - 1)) //Last character is not a digit
- {
- this.errYear.SetError(txtYear, "Invalid character");
- // Add invalid character to the list
- if (!invalidChars.Contains(ctr.Text[ctr.Text.Length - 1]))
- invalidChars += ctr.Text[ctr.Text.Length - 1];
- }
- // Remove the character from list if it was deleted from the textbox
- if (invalidChars.Length > 0)
- if (!ctr.Text.Contains(invalidChars[invalidChars.Length-1]))
- invalidChars = invalidChars.Remove(invalidChars.Length - 1);
- txtResult.Text = invalidChars;
- // Remove error alert
- if (invalidChars.Length == 0)
- this.errYear.Clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement