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

The Archive Base Latest Questions

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

I have a text field which I need to validate using a regex. My

  • 0

I have a text field which I need to validate using a regex. My requirement is as follow:

CCCCNNNNNN or CCCCNNNNNNN (Template)

1234ABCDEFG or 123-ABCDEFG (Example string)

Rules:

  • The whole string is maximum 25 characters
  • The first four characters (CCCC) must be alphanumeric
  • CCCC is 4 characters exactly and can be digits or number
  • CCCC can have a dash sign as 4th character
  • NNNNNNNNNNNN can be up to 21 characters and only numbers

E.g. AAAA 1234 A58- is a valid string for CCCC.

Here is my research notes:

  • I will need to match numerics first
  • I will need the + char to specify to match this pattern X times
  • I will need to match letters after that for 8-9 spaces

There is a wonderful post on RegEx patterns here:

Matching numbers with regular expressions — only digits and commas

My goal is to apply this REGEX pattern to a text box Mask in a WinForms app.

  • 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-26T21:00:47+00:00Added an answer on May 26, 2026 at 9:00 pm

    ….

    ….

    …yeah – I think the answer you are looking for (and I stress “think“) is this expression:

    ^[0-9A-Za-z]{3}[0-9A-Za-z-]\d{0,21}$
    

    thats:

    ^               # assert beginning (not in the middle)
    [0-9A-Za-z]{3}  # three characters that are: 0-9 or a-z (upper or lower)
    [0-9A-Za-z-]    # one character that is: 0-9 or a-z (upper or lower) or a dash
    \d{0,21}        # anywhere from 0 to 21 digits
    $               # assert at the end (not somewhere in the middle
    

    If you want to match several cases of this expression, put the above expression (minus the assertions) into parantheses (()) along with whatever is allowed to separate these values – I chose \s or “whitespace”) and then use the + quantifier:

    ^([0-9A-Za-z]{3}[0-9A-Za-z-]\d{0,21}\s+)+$
    

    will match/validate the following input:

    1234567890 AAAA123456789012345678901 GGG-123       hhh5   A1B2000000000
    

    If you wanted something else, you’ll have to ask a clearer question (there’s a lot of contradiction and repetition in your question that makes it EXTREMELY confusing)

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

Sidebar

Related Questions

I have a text field which has the regex validation and it should not
I have a text field cell in a table view, from which I need
Hi I have a text field which I would like to bind to a
I have an input text field which has style: visibility: visible or style: visibility:
I have an input text field, which has a value something by default, but
I have an input field which has a placeholder text. I want one word
In a SQL server database, I have a table which contains a TEXT field
I have a calculation application which I need to validate the fields to check
I have this page which has several TextAreas (asp.net mvc). I need to validate
I have a form field in Drupal which I need some help with. The

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.