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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:47:09+00:00 2026-05-26T11:47:09+00:00

A colleague uses a application which uses regular expressions to validate data entry fields.

  • 0

A colleague uses a application which uses regular expressions to validate data entry fields.

He needs to allows users to choose from digits 1-9.

i.e. 1, 2, 3, …, 12, 13, …, 23, 24, …, …, 123456789

The obvious basic [1-9]{1,9} would not disallow repeated digits or enforce numerical order.

A digit cannot be repeated (disallow 11, 343, etc.) and they must be in numerical order (disallow 21, 164, etc).

Short of matching the 320 possibilities separately “(1|2|3|…|12|13|…)”, how can I achieve this?

  • 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-26T11:47:10+00:00Added an answer on May 26, 2026 at 11:47 am
    ^1?2?3?4?5?6?7?8?9?$
    

    This one?

    Clearly the user can insert up to 9 digits (123456789) and he can start from any one. Any digit is optional, but the order is fixed.

    If you want a digit to be necessary, use a look ahead

    ^(?=[1-9])1?2?3?4?5?6?7?8?9?$
    

    or look behind

    ^1?2?3?4?5?6?7?8?9?(?<=[1-9])$
    

    or negative look ahead

    ^(?!$)1?2?3?4?5?6?7?8?9?$
    

    or negative look behind

    ^1?2?3?4?5?6?7?8?9?(?<!^)$
    

    so at least a digit is necessary

    If your regex language doesn’t have look aheads (and look behinds) you can do:

    ^12?3?4?5?6?7?8?9?|23?4?5?6?7?8?9?|34?5?6?7?8?9?|45?6?7?8?9?|56?7?8?9?|67?8?9?|78?9?|89?|9)$
    

    Now the first digit “branches” to the “valid” combination of following optional digits.

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

Sidebar

Related Questions

I was wondering if HttpContext.Session uses cookies to store data. A work colleague told
My colleague and I have a web application that uses Spring 3.0.0 and JPA
a colleague pointed me the other day to BCEL which , as best I
A colleague of mine uses a abomination text editor that routinely leaves comment blocks
My application is mostly Java but, for certain calculations, uses a C++ library. Our
I have an application that uses currently two DLL's for external libraries (AjaxControlToolkit is
My colleague has written a DLL which drives Excel. When I reference his DLL
Our application at work uses the ExtJS (Sencha) framework for the UI. The problem
In a discussion, a colleague told me that he never uses enum because he
Today, I've had some debate with my colleague about choosing data types in our

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.