.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Forum >> VB.Net >> Post New QuestionBookmark and Share Subscribe to Forum

textbox validation in windows applcation..

Posted By: gopal     Posted Date: April 24, 2009    Points:2   Category :VB.Net
hi ..

i want to validate a textbox that only accepts numbers and floating point numbers only..
its a windows application..

i need coding in c#..


Author: Athira Sreejith             
Posted Date: April 24, 2009     Points: 5   


You can use validation control.Like this..

<asp:RegularExpressionValidator ID="RegularGiftsQuantity" runat="server" ControlToValidate="txtGiftsQuantity"
Display="None" ErrorMessage="Give Valid Gifts Quantity" ValidationExpression="^[1-9]\d*\.?[0]*$" ValidationGroup="DCR">*</asp:RegularExpressionValidator>

Author: Hefin Dsouza             
Posted Date: April 27, 2009     Points: 5   

Dear Appukuttan , gopal wants a code for validation of textbox in Windows Application.
Try This Code in the text leave event of the textbox do not forget to drag and drop the errorprovider from the toolbox.

int num = Convert.ToInt32(textBox2.Text);
errorProvider1.SetError(textBox2, "");
catch(Exception ex)
errorProvider1.SetError(textBox2, "Only Numbers Allowed");

Regards Hefin Dsouza

Author: Syed Shakeer Hussain             
Posted Date: April 27, 2009     Points: 5   

Hi Gopal

Validating a cellnumber textbox in Windows Form usinr c#

First Add a textbox and button on windows form

Keep name of textbox as textcellno

Double click the button and write below code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{ public partial class Form1 : Form
{ public Form1()
{ InitializeComponent();
private void button1_Click(object sender, EventArgs e)
String str=Convert.ToString(textcellno.Text);
if(str .Length ==10)
String strcell=String.Empty;
for(int i=0;i<10;i ++)

MessageBox.Show("Invalid cellNo");


MessageBox.Show("you cell Number is valid:" + str);
MessageBox.Show("CellNo Should Contain exactly 10 Digits");


Author: Meetu Choudhary             
Posted Date: April 29, 2009     Points: 5   

* What Hussian is said is quite Fine.
* And in addition to this you can also use the keycodes to check it is a number or something else.
* It depends on you at Which event you use it.
* Depending on the funcantly of the application.

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend