Created
May 25, 2012 11:51
-
-
Save vheon/2787574 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 numericOnlyTextBox_KeyUp(object sender, KeyEventArgs e) | |
{ | |
TextBox textBoxControl = sender as TextBox; | |
string[] invalidCharacters = { "*", "#", ",", "(", ")", "x", "-", " ", "@", "." }; | |
for (int index = 0; index < invalidCharacters.Length; ++index) | |
{ | |
textBoxControl.Text = textBoxControl.Text.Replace(invalidCharacters[index], ""); | |
} | |
textBoxControl.SelectionStart = textBoxControl.Text.Length; | |
} | |
private void numericOnlyTextBox_KeyDown(object sender, KeyEventArgs e) | |
{ | |
TextBox textBoxControl = sender as TextBox; | |
int n = 2; //TODO: adjust this as the max number of digits | |
if (textBoxControl.Text.Length > n) | |
{ | |
e.Handled = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment