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

  • Home
  • SEARCH
  • 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 237459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:25:37+00:00 2026-05-11T20:25:37+00:00

long time listener. First time caller… Not strictly a PHP question as it involves

  • 0

long time listener. First time caller…

Not strictly a PHP question as it involves regular expressions but this one has got me tearing my hair out.

I have 3 regular expressions that I want to create, and only one is working correctly.

Now I am not sure whether this is due to the fact that:

  1. I don’t understand preg_match and
    ereg and their return codes as I
    haven’t worked in PHP for about 7
    years.
  2. My regular expressions are
    just plain wrong.
  3. I am mentally disabled.

Either way here are the expressions and my feeble attempts in making them work.

1) Match any number starting with 2,3,4 or 5 then followed by 5 digits. (This one I think works)

code:

if (!ereg('/[2-5]\d{5}/', $_POST['packageNumber' )
{
   echo "The package number is not the correct format.";
}

2) Match any number starting with 2,3,4 or 5 then followed by 5 digits then a period then a 1 or a 2.

if (!ereg("/[2-5]\d{5}\.[1-2]/", $_POST['packageModifier' )
{
   echo "The package modifier is not the correct format.";
}

3) Match any combination of alphanumerics, spaces,periods and hypens up to 50 characters.

if (!ereg("/[0-9a-zA-Z\s\-\.]{0,50}/", $_POST['customerNumber' )
{
   echo "The customer number is not the correct format.";
}

If anyone can please tell me what I am doing wrong I’ll give them my first born.

  • 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-05-11T20:25:37+00:00Added an answer on May 11, 2026 at 8:25 pm

    I’m assuming that you just missed off the closing ] on the $_POSTS and i’ve added in anchors for the start and end of the lines and used preg_match.

    If you don’t anchor it and the pattern is matched anywhere in the string then the entire thing will match. For example.

    “dfasfasfasfasf25555555as5f15sdsdasdsfghfsgihfughd54” would be matched if the first one was not anchored.

    Number One

    if (!preg_match('/^[2-5]\d{5}$/', $_POST['packageNumber'])) {
     echo "The package number is not the correct format.";
    }
    

    Number Two

    if (!preg_match('/^[2-5]\d{5}\.[2-5]$/', $_POST['packageModifier'])) {
      echo "The package modifier is not the correct format.";
    }
    

    Number Three

    if (!preg_match('/^[0-9a-zA-Z\s\-.]{0,50}$/m', $_POST['customerNumber'])) {
     echo "The package modifier is not the correct format.";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 211k
  • Answers 211k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer >>> import urllib2 >>> urllib2.quote('한글') '%ED%95%9C%EA%B8%80' May 12, 2026 at 10:09 pm
  • Editorial Team
    Editorial Team added an answer I guess that what you are looking for is Atlassian… May 12, 2026 at 10:09 pm
  • Editorial Team
    Editorial Team added an answer Maybe try some work on a reasonable sized Open Source… May 12, 2026 at 10:08 pm

Related Questions

Long time listener, first time caller. I'm a full time SE during the day
long time listener. First time caller... Not strictly a PHP question as it involves
I have a pretty simple question which perhaps someone familiar with Server/Client design &
Hello everyone Masters Of Web Delevopment :) I have a piece of PHP script
I'm a long-time ActionScript 2 user, now getting started with ActionScript 3. The one

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.