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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:43:43+00:00 2026-05-28T03:43:43+00:00

I’ve written a Regular expression which should validate a string using the following rules:

  • 0

I’ve written a Regular expression which should validate a string using the following rules:

  1. The first four characters must be alphanumeric.
  2. The alpha characters are followed by 6 or 7 numeric values for a total length of 10 or 11.

So the string should look like this if its valid:

CCCCNNNNNN or CCCCNNNNNNN

C being any character and N being a number.

My expression is written: @"^[0-9A-Za-z]{3}[0-9A-Za-z-]\d{0,21}$";

My regex match code looks like this:

var cc1 = "FOOBAR"; // should fail.
var cc2 = "AAAA1111111111"; // should succeed

var regex = @"^[0-9A-Za-z]{3}[0-9A-Za-z-]\d{0,21}$";

Match match = Regex.Match( cc1, regex, RegexOptions.IgnoreCase );

if ( cc1 != string.Empty && match.Success )
{
     //"The Number must start with 4 letters and contain no numbers.",
     Error = SeverityType.Error
}

I’m hoping someone can take a look at my expression and offer some feedback on improvements to produce a valid match.

Also, am I use .Match() correctly? If Match.Success is true, then does that mean that the string is valid?

  • 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-28T03:43:44+00:00Added an answer on May 28, 2026 at 3:43 am

    The regex for 4 alphanumeric characters follows by 6 to 7 decimal digits is:

    var regex = @"^\w{4}\d{6,7}$";
    

    See: Regular Expression Language – Quick Reference


    The Regex.Match Method returns a Match object. The Success Property indicates whether the match is successful or not.

    var match = Regex.Match(input, regex, RegexOptions.IgnoreCase);
    
    if (!match.Success)
    {
        // does not match
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.