I have problem in Numeric TextBox

Posted by Nuwan under C# on 5/1/2012 | Points: 10 | Views : 1182 | Status : [Member] | Replies : 5
i have a windows application in c#. It have one text box. I want to enter it numeric value only.
How i validate that text box, please help me.

Thank you.

Rathnayake


Responses

Posted by: Leila on: 5/1/2012 [Member] Starter | Points: 25

Up
0
Down
you can put the validation on keypress event.
the following link may help you
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress.aspx

Thanks,
Leila

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mahesh_Chs on: 5/1/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

Try this

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!Char.IsDigit(e.KeyChar))
{
MessageBox.Show("enter the digits only");
e.Handled = true;
}
}

Regards
Mahesh

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Taanu51 on: 5/3/2012 [Member] Starter | Points: 25

Up
0
Down
we have another way to validate the textbox using Jquery

http://www.developerscode.com/2011/09/allow-only-numerics-using-jquery-in.html

Check this..it may helps you

Tanisha Sayyad
.Net and Android Developer
INDIA(Andhra Pradesh)

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Reza_M_N_65 on: 7/1/2013 [Member] Starter | Points: 25

Up
0
Down
a complete Numerical TextBox class for download

All what you need there is in this project.
http://www.mediafire.com/download/fidd3mm85dmq9tb/%281392.03.10%29_Numerical_TextBox_Sample.rar
download this code to learn how to create a Numerical TextBox.
in this Folder there is a `NumericalTextBoxes.dll` file. you can using this NumericalTextBoxes.dll file in your project and that is enough to create a `NumericalTextBox` and set it's Text using `Text property` and get it's Text using `NumericalText property` of your NumericalTextBox easily. for more help refer to `Form1.cs` code in (1392.03.10) NumericalTextBoxSample\NumericalTextBoxSample\Form1.cs or open project by clicking (1392.03.10) NumericalTextBoxSample\NumericalTextBoxSample.sln and run it and see All what you need.
Reza_m_n_65

Reza_m_n_65

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 7/2/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Number_Character_validate_Csharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
// Number Validation(only Number allowed)
if (!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), "\\d+"))
{
e.Handled = true;
}

}
}
}


If this post helps you mark it as answer
Thanks

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response