I want to make sure that the Input of my Textbox is of a specific Format.
+101.800
-085.000
+655.873
The correct length aswell as the +/- Symbol is important for communication in the process.
I thought about using a MaskedTextbox
but that wouldn't force the user to add the +/-Symbols if I understand the documentation correctly.
You can write in Leave event for check value after leaving textbox and make text color red if that is wrong value for user's attention and disable submit button for preventing to press button before write the number in correct format.
private void myInput_Leave(object sender, EventArgs e)
{
Regex r = new Regex(@"^[+-]?[0-9]{3}\.[0-9]{3}$");
Match m = r.Match(InputTextbox.Text);
if (!m.Success)
{
myInput.ForeColor = Color.Red; // Text color will go red
submitBtn.Enabled = false; // Submit button is disabled now
}
else
{
myInput.ForeColor = Color.Black;
submitBtn.Enabled = true; // Submit button is enabled now
}
}