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 6758015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:43:26+00:00 2026-05-26T13:43:26+00:00

I give up. I need a (PHP) regular expression that matches only 5 digit

  • 0

I give up. I need a (PHP) regular expression that matches only 5 digit numbers starting from 01001 up to 99998.

So, invalid is for example 1234, but not 01234. Also 01000 is invalid, 01002 is not, and so on. Any other 5 digit number except 99999 is valid.

What I have is the following regular expression, which does what I require – except that it still matches 99999.

Can anyone help out? Thanks…

^01\d\d[1-9]|[1-9]\d{3}[(?<=9999)[0-8]|[0-9]]$

Update

I am sorry, everybody, but things are more complex. I did not explain correctly.
German zip code can be also 04103 for example (see a list of some further examples here)

  • 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-26T13:43:27+00:00Added an answer on May 26, 2026 at 1:43 pm

    You were close:

    ^0[1-9]\d\d(?<!0100)0|0[1-9]\d\d[1-9]|[1-9]\d{3}[0-8]|[1-9]\d{3}(?<!9999)9$
    

    But if you can just do a simpler regex and then use a separate numerical comparison, that’d probably be easier to read.

    Alternatively, a simpler version:

    ^(?!01000|99999)(0[1-9]\d{3}|[1-9]\d{4})$
    

    (The simpler version is just “take the numbers 01000–99999 and remove the two ends via a lookahead.)

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

Sidebar

Related Questions

Hi I need a regular expression that'll give me something like this part ./something\,
I need a regex that will give me the following results from each example
I need to extract some data from a webpage with php. The part that
I would need a regular expression that escapes or captures (if not already escaped)
i need Enumarable value from below class but give error public static Enumerable LoadDataByName(string
I need to run a PHP CLI script and give it a LOT of
I have a command line php app that I need to distribute to a
I need to call a Perl script from a PHP file, and I've gotten
I need a base_convert() function that works from base 2 up to base 62
I need to create a PHP class that would send e-mails to all 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.