Allow Only Numbers in TextBox Windows Forms using regular expression
Today, We want to share with you Allow Only Numbers in TextBox Windows Forms using regular expression.In Allow Only Numbers in Textbook Windows Forms post we will show you allow only decimal values in text box c#, hear for how to validate a textbook in c# to accept only numeric value we will give you demo and example for implement.In this post, we will learn about allow only numbers in text box c# using regular expression with an example.
TextBox Accepting Only Numbers in Windows Forms
In this post, we will learn about how to create TextBox Accepting Only Numbers in Windows Forms with an example.
Now in this post, I will explain about creating TextBox Accepting Only Numbers in Windows Forms with appropriate example.
Many a times you come across a situation wherein you want to allow only Numbers in text-box for ex. Count of member, Count of dishes etc. You can make use of Key-press event of text-box in win form to check which key is pressed and accordingly you can prevent any other key pressed by user.
Now MakeWindows Form Application in Visual Studio and write below lines of code in it.
private void txtRate_KeyPress(object sender, KeyPressEventArgs e)
e.Handled = !char.IsDigit(e.KeyChar); // Does not allow backspace
If you want to allow backspace and numeric then use below lines of codes.
<pre class="EnlighterJSRAW" data-enlighter-language="null">private void txtRate_KeyPress(object sender, KeyPressEventArgs e)
e.Handled = !char.IsDigit(e.KeyChar); // This line allow numeric and backspace
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about Text box to accept only numbers in C# windows Forms C# .NET.I would like to have feedback on my Pakainfo.com blog.Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.
We would like to have Good feedback on my Information Website Information blog .
We hope This Post can help you…….Good Luck!.