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");
}
}
}
}