Last active
August 29, 2015 14:10
-
-
Save arslanbilal/6377eae97157f93bc053 to your computer and use it in GitHub Desktop.
Entering only numbers and just one "." character into the textBox in C#
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 textBoxKeyPressNumber(object sender, 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 TextBox).Text.IndexOf('.') > -1)) | |
{ | |
e.Handled = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment