The text box is used to list the Name of a Course that is being stored in database. Don't want to go to the extreme of concatenating the string to pass it to the data base
Well there are two other methods I have for you then. Either:
A) Catch each letter coming and going from the textbox, and if it doesnt fit the pattern, dissallow it (or inform the user somehow). Something like:
-
void TextBox1_TextChanged(object sender, EventArgs e)
-
{
-
for (int i = 0; i < 3 && i < ((TextBox)sender).Text.Length; i++)
-
{
-
if (!IsAlpha(((TextBox)sender).Text[i]))
-
{
-
InformUserOfBadCharacter(i);
-
}
-
}
-
-
if (((TextBox)sender).Text.Length > 3)
-
{
-
if (((TextBox)sender).Text[3] != '.')
-
{
-
InformUserOfBadCharacter(3);
-
}
-
}
-
-
for (int i = 4; i < 7 && i < ((TextBox)sender).Text.Length; i++)
-
{
-
if (!IsNumeric(((TextBox)sender).Text[i]))
-
{
-
InformUserOfBadCharacter(i);
-
}
-
}
-
}
-
-
static bool IsAlpha(char test)
-
{
-
return (test >= 65 && test <= 90) || (test >= 97 && test <= 122);
-
}
-
-
static bool IsNumeric(char test)
-
{
-
return test >= 48 && test <= 57;
-
}
-
or
B) Create a property that fakes the two text box's values in the example I gave above. Something like:
-
public string CourseName
-
{
-
get { return string.Format("{0}.{1}", TextBox1.Text, TextBox2.Text); }
-
}
-
Setting it would run through the same difficulties as method A. You would need to make sure the value is of valid size, and then of valid input. If not, I would probably throw an exception to be handled else where.