Skip to content

Instantly share code, notes, and snippets.

@jorabra
Created October 31, 2011 12:23
Show Gist options
  • Save jorabra/1327378 to your computer and use it in GitHub Desktop.
Save jorabra/1327378 to your computer and use it in GitHub Desktop.
TextBox KeyPress decimal number input validation.
private void ValidateKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.')
{
e.Handled = true;
}
// Only allow one decimal point
if (e.KeyChar == '.' && (sender as StxTextBox).Text.IndexOf('.') > -1)
{
e.Handled = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment