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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:04:44+00:00 2026-06-16T05:04:44+00:00

I want to validate input in a C# TextBox by using regular expressions. The

  • 0

I want to validate input in a C# TextBox by using regular expressions. The expected input is in this format:
CCCCC-CCCCC-CCCCC-CCCCC-CCCCC-CCCCC-C

So I’ve got six elements of five separated characters and one separated character at the end.

Now my regex matches any character between five and 255 chars: .{5,255}

How do I need to modify it in order to match the format mentioned above?

  • 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-16T05:04:45+00:00Added an answer on June 16, 2026 at 5:04 am

    Update: –

    If you want to match any character, then you can use: –

    ^(?:[a-zA-Z0-9]{5}-){6}[a-zA-Z0-9]$
    

    Explanation: –

    (?:                // Non-capturing group
        [a-zA-Z0-9]{5} // Match any character or digit of length 5
        -              // Followed by a `-`
    ){6}               // Match the pattern 6 times (ABCD4-) -> 6 times
    [a-zA-Z0-9]        // At the end match any character or digit.
    

    Note: – The below regex will only match pattern like you posted: –

    CCCCC-CCCCC-CCCCC-CCCCC-CCCCC-CCCCC-C
    

    You can try this regex: –

    ^(?:([a-zA-Z0-9])\1{4}-){6}\1$
    

    Explanation: –

    (?:                // Non-capturing group
      (                // First capture group
        [a-zA-Z0-9]    // Match any character or digit, and capture in group 1
      )
      \1{4}            // Match the same character as in group 1 - 4 times
      -                // Followed by a `-`
    ){6}               // Match the pattern 6 times (CCCCC-) -> 6 times
    \1                 // At the end match a single character.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to validate mathematical expressions using regular expression. The mathematical expression can be
How to validate a mobile number textbox and email textbox using regular expressions in
i am using a form with several textbox elements which i want to validate
i want to validate user input for alphanumeric characters and for that im using
Hi I want to validate a form using a button, but this button call
We are using a RegEx Validator to validate an input from a textbox. The
i want to validate input during form submit for textbox B if it is
I need to validate some textbox input. I want to use a regex. The
I am using a javascript to validate input from a textbox that's inside a
I am using ASP.NET Regular Expression Validator to validate a textbox . Valid Samples:

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.