Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8654473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:47:47+00:00 2026-06-12T14:47:47+00:00

For a class I need to do a preg_match for a phone number. The

  • 0

For a class I need to do a preg_match for a phone number. The number must match this format (###) ###-####. If the format is incorrect I need to send the user to the form to have the number filled out again. If a match is found I need to allow the form to go through.

My instructor had us write it as such:

$PhonePattern = "\(\d\d\d\) \d\d\d-\d\d\d\d";
if (!preg_match($PhonePattern, $Phone))
{
header('location:CreateAccount.htm');
exit();
}
else 
{
$Phone = $_GET['txtPhone'];
}

This does not work. Can it be changed to:

if (!preg_match('/\(\d\d\d\) \d\d\d-\d\d\d\d/', $Phone))
{
header('location:CreateAccount.htm');
exit();
}
else 
{
$Phone = $_GET['txtPhone'];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:47:48+00:00Added an answer on June 12, 2026 at 2:47 pm

    The following is one way:

    '/^\(\d{3}) \d{3}-\d{4}$/'
    

    I added anchors and repetition. Otherwise, you were close.

    Learn more about regular expressions. They are a power tool. But with great power, comes great responsibility.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this line in php <a title='.htmlspecialchars($User->Name).' href='.$Href.''.$LinkClass.'> I need to add another
I have a program for a C class I need to write. The program
I have a problem to test my non activity-class which need the context of
I need a class that works like this: >>> a=Foo() >>> b=Foo() >>> c=Foo()
I need B class to have a min priority queue of AToTime objects. AToTime
I have a sample class where I need to specialize the Print function if
In php have a class SoapClient I need a equivalente class in Java, anyone
I need to get this working: PHP First match should look for the following:
I need a php validator class that validates user inputs. I want it to
Possible Duplicate: Why XML-Serializable class need a parameterless constructor Does anyone know if it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.