Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

how can i make a validation for this code for the name? it has to be at least one character long, after being trimmed. It

how can i make a validation for this code for the name? it has to be at least one character long, after being trimmed. It has to test for a valid value. if it is invalid then set the area code attribute to string . Empty

public class Telephone { public string sName { get { return sName; } set { sName = value; } } public int iAreaCode { get { return iAreaCode; } set { iAreaCode = value; } } public int iPhoneNumber { get { return iPhoneNumber; } set { iPhoneNumber = value; } }

public bool Valid { get { return this.Valid; } set { this.Valid = value; } }

static void Main(string[] args) {

Telephone person = new Telephone();

string sName; int iAreaCode; int iPhoneNumber; bool AreaCodevalid; bool PhoneNumber;

Console.Write("Please Enter Person's Name: "); sName = Console.ReadLine().Trim();

Console.Write("Please enter the area code: "); int.TryParse(Console.ReadLine().Trim(), out iAreaCode);

if (((iAreaCode >= 100) && (iAreaCode <= 799) || (iAreaCode >= 900) && (iAreaCode <= 999))) { AreaCodevalid = true; } else { AreaCodevalid = false; } Console.WriteLine("INVALID - must be 100-799 or 900 - 999 {0}", AreaCodevalid);

Console.Write("Please enter the number: "); int.TryParse(Console.ReadLine().Trim(), out iPhoneNumber);

Console.WriteLine();

if (((iPhoneNumber >= 1000000) && (iPhoneNumber <= 9999999))) { PhoneNumber = true; } else { PhoneNumber = false; } Console.WriteLine("INVALID - must have 7 digits {0}", PhoneNumber);

Console.WriteLine(" ");

printContact(sName, iAreaCode, iPhoneNumber); } static void printContact(string sName, int iAreaCode, int iPhoneNumber) { Console.WriteLine("Contact Information:"); Console.WriteLine("===================="); Console.WriteLine("Name: {0} Telephone number: {1}-{2} ", sName, iAreaCode, iPhoneNumber); // ** Complete this line using properties

Console.Write("Press any key to exit..."); Console.ReadKey(); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions