Answers for "c# check if textbox contains only numbers"

C#
1

check textbox is only numbers + c#

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    // Verify that the pressed key isn't CTRL or any non-numeric digit
    if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
    {
        e.Handled = true;
    }

    // If you want, you can allow decimal (float) numbers
    if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
    {
        e.Handled = true;
    }
}
Posted by: Guest on September-16-2020
2

c# check if string is only letters and numbers

if (textVar.All(c => Char.IsLetterOrDigit(c))) {
    // String contains only letters & numbers
}
Posted by: Guest on May-19-2020

Code answers related to "c# check if textbox contains only numbers"

C# Answers by Framework

Browse Popular Code Answers by Language