Question: Part B Research online about pattern matching and regular expressions. What is a regular expression? Locate an example online and explain what it does: ____________________________

Part B

Research online about pattern matching and regular expressions.

What is a regular expression?

Locate an example online and explain what it does: ____________________________

We are going to use the following regular expression to search for a phone number: \(?\d{3}\)?[. -]? *\d{3}[. -]? *[. -]?\d{4}

What does the \d indicate?

What does the {3} indicate?

Feel free to create a form/GUI or use console to create a regular expression to determine if a phone number input is valid. You will need to import a regular expression library. My code below as an example:

string phoneNum =txtName.Text;

string MatchPhonePattern = @"\(?\d{3}\)?[. -]? *\d{3}[. -]? *[. -]?\d{4}";

Regex rx = new Regex(MatchPhonePattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);

Match match = rx.Match(phoneNum);

if (match.Success)

lblDisplay.Text = "Valid number";

else

lblDisplay.Text = "not valid";

Run your program and include a screenshot of your code running and copy and paste your code. Use phone number as a regular expression, then validate a social security number using regular expressions.

Code for Phone number regex:

Screenshot:

Code for Social Security number regex:

Screenshot:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!