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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:09:02+00:00 2026-06-01T18:09:02+00:00

How to write regex to validate this pattern? 123456 – correct *1 – correct

  • 0

How to write regex to validate this pattern?

123456 - correct
*1 - correct
1* - correct
124** - correct
*1*2 - correct
* - correct
123456* - incorrect (size 7)
12345 - incorrect (size 5 without stars)

tried:

^[0-9]{6}$|^(([0-9]){1,6}([*]){1,5}){1,6}+$

But it allows to have more than 6 numbers and don’t allow for star to be before number.
There is no minimum/maximum count of “*” sign (but max count for all signs is 6).

  • 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-01T18:09:03+00:00Added an answer on June 1, 2026 at 6:09 pm

    Here you go:

    ^(?:\d{6}|(?=.*\*)[\d*]{1,6}|)$
    

    Here is what it does:

    ^            <-- Start of the string (we don't want to capture more than that)
      (?:          <-- Start a non captured group (it will be used to do the "or" part)
        \d{6}          <-- 6 digits, nothing more
        |            <-- OR
        (?=.*\*)       <-- Look ahead for a '*' (you could replace the first * with {0,5})
        [\d*]          <-- digits or '*'
        {1,6}          <-- repeated one to six times (we know from the look ahead that there will be at least one '*'
        |            <-- OR (nothing)
      )            <-- End the non capturing group
    $            <-- End of the string
    

    I’m not quite sure if you want the empty case (but you said 0 to 6), if you actually want 1 to 6 just remove the last |

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

Sidebar

Related Questions

I'm trying to write a a regex to validate a string to match the
Is there any way to write a Regex that can validate one type of
I'm trying to write a regex to validate part or model numbers. These can
I have a requirement to write a regex to validate a text entry. The
Wanna write a RegEx to validate a driving license. if it doesn't start with
I want to write a function validate() which will take some pattern or regular
I want to validate a phone number this format +905555555555. How can I write
I am trying to write a regex which will validate the format of a
How would one write a regex that matches a pattern that can contain quotes,
I wanted to write a regex to count the number of spaces/tabs/newline in a

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.