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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:34:45+00:00 2026-06-14T05:34:45+00:00

I am trying to generate regex for the following number range… It is mandatory

  • 0

I am trying to generate regex for the following number range…

It is mandatory that I need to have the 00001 or 0000001 as the starting number

ISRAEL  NNNNN   00001   99999
        NNNNNNN 0000001 9999999

I am trying with this regex: ^0*[0-9]{5}$|^0*[0-9]{7}$

But it fails for the following scenarios. It accepts these number which shouldn’t be.

0100012
000010121
  • 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-14T05:34:46+00:00Added an answer on June 14, 2026 at 5:34 am

    I think that what OP is trying to ask is how to write a regular expression that ensures that of all 5 or 7 digits at least one is non-zero (probably zip-code can’t be all zeros).

    Obviously, it is much easier to do this w/o using a regular expression. Parse integer, see if it is greater then zero and less then 100000 or 1000000, and you are done. Of course, if you want to force your users to input extra zeros in front of the code… that’s your choice. Users comply with even weirder demands nowadays.

    But if you felt challenged by the task complexity, and wanted it to be done by using regular expression no matter the price, then here you go:

    ^(?:0*[1-9]0*)+$
    

    This would ensure that all the characters of the string are digits, and that at least one of them is non-zero. Additionally checking the length of the string, you’d figure out if it’s equal 7 or 5. (This is a relatively easy way).

    The hard way:

    ^\d{4}[1-9]|\d{3}[1-9]\d|\d{2}[1-9]\d{2}|\d[1-9]\d{3}|[1-9]\d{4}$
    

    (This is for 5-digit zip codes, you are welcome to try to extend it to 7-digit zip-codes) 😛

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

Sidebar

Related Questions

I'm trying to generate a report of the activities that users have done within
Ok, I have a SQL query that I'm trying to generate that will combine
I'm trying to generate the following html code using cl-who: <html> <body> <div id=cnt_1></div>
I have been trying to generate report as per age differences of different months
I'm trying to generate 16 000 000 unique random numbers (10-digits: range 1 000
Problem: I have a servlet that generate reports, more specifically the table body of
I have some tests that use guids. The guids used don't need to be
I'm trying to write a regex function that will identify and replace a single
I am new to using cfajaxproxy, I am trying to have select a number
I'm trying to understand why the following returns false: (** I should have put

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.