Code:
private string code = string.Empty;
private void txtCodeInput_TextChanged(object sender, EventArgs e)
{
code = txtCodeInput.Text;
if (code.Contains("-"))
{
code.Replace("-", string.Empty);
}
Regex rx = new Regex(@"[a-zA-Z]");
if (rx.Match(code).Success)
{
MessageBox.Show("Invalid code entered. Code can be 1-25 digits long. Alpha characters not allowed.",
"Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
code = string.Empty;
}
if (code.Length > 25)
{
MessageBox.Show(
"Maximum code length is 25! Please check your code again." + Environment.NewLine + "You have " +
code.Length + " digits supplied.", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
Sorry, too lazy to VB convert. Enjoy. (Allows the - separator to be used)