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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:46:53+00:00 2026-05-29T20:46:53+00:00

Can we use regular expressions to find out if a string follows these rules?

  • 0

Can we use regular expressions to find out if a string follows these rules?

  • Not have upper-case letters.
  • Begin with a letter.
  • Have at least 1 digit(s) not at the beginning and end.
  • Have up to 8 alphanumeric
  • Does NOT have any symbols like @#$ characters (symbols like !@#$%^&*()-+).
  • 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-29T20:46:56+00:00Added an answer on May 29, 2026 at 8:46 pm

    EDIT: I’ve updated the regular-expression in the code with one which looks to work.

    @"^[a-z](?=[a-z0-9@#\$]*[0-9][a-z0-9@#\$]*)[a-z0-9@#\$]{0,6}[a-z@#\$]$"

    EDIT: I’ve tweaked the code. One of the tests was aa1@aaaa marked as being expected to fail when it should succeed as pointed out by Douglas.

    I’ve verified that the regular-expression offered by Douglas works just as well and its shorter too.


    Not an answer as such, but here’s a quick test-rig. I’ve used the regular expression and tests from @ShaunWilde’s answer.

    Unfortunately, the tests don’t return the expected results :-|.

    using System;
    using System.Collections.Generic;
    using System.Text.RegularExpressions;
    
    namespace StackOverflow.RegularExpressions
    {
        internal class Program
        {
            private static void Main(string[] args)
            {
                var validString =
                    new Regex(@"^[a-z][a-z\d!@#$%\^&*()\-+]{0,7}$(?<=\d\D+)",
                              RegexOptions.Compiled);
    
                var testsAndExpectedResults = new List<Tuple<string, bool>>
                                                  {
                                                      new Tuple<string, bool>("a1@aaaaa", true),
                                                      new Tuple<string, bool>("a@1aaaaa", true),
                                                      new Tuple<string, bool>("aa@aaaaa", false),
                                                      new Tuple<string, bool>("a1@aaaaaaa", false),
                                                      new Tuple<string, bool>("a1@aaaa", true),
                                                      new Tuple<string, bool>("1a1@aaaa", false),
                                                      new Tuple<string, bool>("aa1@aaaa", true),
                                                      new Tuple<string, bool>("Aa1@aaaa", false),
                                                      new Tuple<string, bool>("Aa1@aaaA", false),
                                                      new Tuple<string, bool>("aA1@aaaA", false),
                                                      new Tuple<string, bool>("#A@a1aaaaa", false)
                                                  };
    
                testsAndExpectedResults.ForEach(t =>
                                                Console.WriteLine("With '{0}' expected {1}, got {2}", t.Item1, t.Item2,
                                                                  validString.IsMatch(t.Item1))
                    );
    
                Console.ReadKey();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find a single regular expression that I can use to parse
What regular expression can I use (if any) to validate that a given string
I'd like to use regular expressions to extract information out of some chat logs.
I generally stay away from regular expressions because I seldom find a good use
I'm trying to parse through a string with regular expressions (.NET) and find all
I'm trying to use the find/adding/removing string/regular expression option in gitk. The syntaxes I
I have a regular expression for use with awk to find any of the
Is there any regular expression library that i can use with CString of vc6?
I'm need a regular expression in Java that I can use to retrieve the
You can use SelectFolder() to get a folder or GetOpenFolderitem(filter as string) to get

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.