Question

In: Computer Science

Write the correct regular expression pattern for a phone number field with the format XXX-XXX-XXXX

  1. Write the correct regular expression pattern for a phone number field with the format XXX-XXX-XXXX

Solutions

Expert Solution

PROC TELEPHONE_NUMBER

postproc

  if regexmatch(TELEPHONE_NUMBER, "^([0-9]{3}-){2}[0-9]{4}$") = 0 then
  errmsg("Invalid format! Use the following format: xxx-xxx-xxxx.");
  reenter;
  endif;

OR

<asp:regularexpressionvalidator validationexpression="”\d{3}-\d{3}-\d{4}”ControlToValidate=”txtPhone”" id="”RegExpVal_txtPhone”" runat="”server”" errormessage="”Invalid" format="" (="" use:="" xxx-xxx-xxxx)”="" display="”Dynamic”"></asp:regularexpressionvalidator>

code in action, run the example

protected bool IsValidPhone(string strPhoneInput)
{
   // Remove anything that is not a number
   string strPhone = Regex.Replace(strPhoneInput, @"[^\d]", String.Empty);

   txtPhone2.Text = strPhone;

   // Check for exactly 10 numbers left over
   return (strPhone.Length == 10);
}


Related Solutions

Create a program that creates and prints a random phone number using the following format: XXX-XXX-XXXX....
Create a program that creates and prints a random phone number using the following format: XXX-XXX-XXXX. Make sure your output include the dashes. Do not let the first three digits contain an 8 or 9 (HINT: do not be more restrictive than that) and make sure that the second set of three digits is not greater than 773. Helpful Hint: Think though the easiest way to construct the phone number. Each digit does do not have to be determined separately....
Q1 Write a python regular expression to match a certain pattern of phone number.             ###...
Q1 Write a python regular expression to match a certain pattern of phone number.             ### Suppose we want to recognize phone numbers with or without hyphens. The ### regular expression you give should work for any number of groups of any (non- ### empty) size, separated by 1 hyphen. Each group is [0-9]+. ### Hint: Accept "5" but not "-6" ### FSM for TELEPHONE NUMBER IS: # state:1 --[0-9]--> state:2 # state:2 --[0-9]--> state:4 # state:2 --[\-]---> state:3 #...
In.java A phone number has the format (xxx)yyy-zzzz ( e.g.(942)731-2262 ). Write a program that reads...
In.java A phone number has the format (xxx)yyy-zzzz ( e.g.(942)731-2262 ). Write a program that reads a string and formats it as a phone number. First it should check that the string has exactly 10 symbols. If it does, the program will print the formatted version. If the string does not have exactly 10 symbols, print Invalid and do not process it. You do NOT need to verify that the symbols in the string are digits. Sample run 1... This...
Pattern matching using python3 re module Write a regular expression that will find out all the...
Pattern matching using python3 re module Write a regular expression that will find out all the words that ends with 4 consecutive vowels at the end. Example: import re f=open("/usr/share/dict/american-english",'r') pattern='a[a-z]*d$' words=f.readlines() matchlist=[word for word in words if re.match(pattern,word)] =============================== Generate random string follow a specific pattern You will take a username and ask user for the password. User has to enter a strong password in order to create his or her account. The criteria for strong password is, a)...
1. What is a regular expression? Write a regular expression that will detect “College” and “collegE”....
1. What is a regular expression? Write a regular expression that will detect “College” and “collegE”. 2. What is degree centrality? Create a graph of 4 vertices and compute the degree centrality of the vertices. 3. Compute internal and external community densities for a graph containing 6 nodes. You can create any graph of 6 nodes with at least 4 edges.
Write Python class that takes a string and returns with a valid phone number. Number format...
Write Python class that takes a string and returns with a valid phone number. Number format is ten-digit numbers consisting of a three-digit area code and a seven-digit number. Clean up different telephone numbers by removing punctuation, and removing incorrect format and the country code (1). You should throw a ValueError with a string if there are too many or too few digits, or the wrong digits. For example, the strings: +1 (617) 111-0000, 617-111-0000, 1 617 111 0000, 617.111.0000...
Write a regular expression, using the regular expression syntax used by lex, that matches any finite...
Write a regular expression, using the regular expression syntax used by lex, that matches any finite decimal representation of a nonnegative real number.
Write a program for XXX Phones, a provider of cellular phone service. Prompt a user for...
Write a program for XXX Phones, a provider of cellular phone service. Prompt a user for maximum monthly values for talk minutes used, text messages sent, and gigabytes of data used, and then recommend the best plan for the customer’s needs. A customer who needs fewer than 400 minutes of talk and no text or data should accept Plan A at $29 per month. A customer who needs fewer than 400 minutes of talk and any text messages should accept...
Q1. 1. The phone numbers collected from questionnaire is a mess. Design a regular expression to...
Q1. 1. The phone numbers collected from questionnaire is a mess. Design a regular expression to filter out those numbers that are stored in the standard format "+00-0-0000-0000" from the file called "Q1.txt". Q1.txt +61392144979 +61 39214 4778 +61-3-9214-4980 +66(2)51574430 +61-3-9285-7706 Note: Only +61-3-9214-4980 and +61-3-9285-7706 are the valid results.
The phone numbers collected from questionnaire is a mess. Design a regular expression to filter out...
The phone numbers collected from questionnaire is a mess. Design a regular expression to filter out those numbers that are stored in the standard format         “+00-0-0000-0000” from the file called “Q1.txt” and redirect the results to the “cleaned.txt”. Note: Only +61-3-9214-4980 and +61-3-9285-7706 are the valid results.    [10 Marks]
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT