Skip to content

Instantly share code, notes, and snippets.

@arslanbilal
Last active August 29, 2015 14:10
Show Gist options
  • Save arslanbilal/86503e62f4f0590d0318 to your computer and use it in GitHub Desktop.
Save arslanbilal/86503e62f4f0590d0318 to your computer and use it in GitHub Desktop.
Entering only letters and just one " " character into the textBox in C#
private void textBoxKeyPressLetter(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsLetter(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