how to validate phone number in windows application

Posted by Chaithragm under C# on 4/15/2013 | Points: 10 | Views : 25116 | Status : [Member] | Replies : 3
Im using this code but its not working

private void phone_txt_Validating(object sender, CancelEventArgs e)
{
if (phone_txt.Text.Length == 10)
{
String strcell = String.Empty;
for (int i = 0; i < 10; i++)
{
if (Char.IsDigit(phone_txt.Text[i]))
{

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

}

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

}




Responses

Posted by: Learningtorise on: 4/15/2013 [Member] Starter | Points: 25

Up
0
Down
http://blog.scosby.com/post/2010/02/11/Validation-in-Windows-Forms.aspx

http://hashtagakash.wordpress.com/

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

Posted by: Raj.Trivedi on: 4/16/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello

Check this

http://www.codeproject.com/Articles/13922/Validate-user-input-in-Windows-Forms

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

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

Posted by: Hi.Sethu on: 4/17/2013 [Member] Starter | Points: 25

Up
0
Down
This can be done using Regular Expressions. Please try this:
System.Text.RegularExpressions.Regex.Match(phone_txt.Text, "\d10+")

Sethumadhavan R
[sethu_vb@hotmail.com]

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

Login to post response