I created a program that takes a phone number and divides it into three parts (AAA) EEE - NNNN. I need it to give a default area code if the user doesnt enter one. Heres what I have so far.
private void btnValidate_Click(object sender, EventArgs e)
{
//declare phone number
string phoneDigits;
string exchange;
string areaCode;
string number;
phoneDigits = txtNumber.Text;
areaCode = phoneDigits.Substring(0,3);
exchange = phoneDigits.Substring(3,3);
number = phoneDigits.Substring(6,4);
txtA.Text = areaCode;
txtE.Text = exchange;
txtN.Text = number;
}
}
The program should also accept AAA.EEE.NNNN as a valid phone number, too. (That is, the separation character between the area code, exchange, and number can be either a hyphen or a period.) If the number entered does not fit this format, you should issue an error message that asks them to re-enter the phone number.
Visual C# programming help?
I'd study regular expressions to help you determine the validity of the strings. There are many online tools that help you evaluate strings with this standard approach.
Query: "Regular Expression Telephone Number"
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment