How to validate a Cell Number in Windows foms

Syedshakeer
Posted by in C# category on for Beginner level | Views : 2360 red flag

How to validate a Cell Number in Windows foms

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 ++)
{
if(Char.IsDigit(str[i]))
{

}
else
{
MessageBox.Show("Invalid cellNo");
break;
}
}

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

}
}
}

 

Page copy protected against web site content infringement by Copyscape

About the Author

Syedshakeer
Full Name: Syed Shakeer Hussiain P
Member Level:
Member Status: Member
Member Since: 2/5/2009 3:12:18 AM
Country: India
Syed Shakeer Hussain
http://www.dotnetfunda.com
Shakeer Hussain has completed his Master of Computer Applications degree from Deccan College of engg and technology of Osmania University.He is a MVM of www.dotnetspider.com.He has good experience in the areas of ASP.NET, C#.NET, VB.NET, SQL SERVER 2000/2005 and Windows Mobile. He has worked in Windows Mobile,Web Applicatin and ERP projects.

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)