Created
October 31, 2011 12:23
-
-
Save jorabra/1327378 to your computer and use it in GitHub Desktop.
TextBox KeyPress decimal number input validation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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