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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:42:01+00:00 2026-05-17T17:42:01+00:00

I really know very little about regex’s. I’m trying to test a password validation.

  • 0

I really know very little about regex’s.
I’m trying to test a password validation.

Here’s the regex that describes it (I didn’t write it, and don’t know what it means):

private static string passwordField = "[^A-Za-z0-9_.\\-!@#$%^&*()=+;:'\"|~`<>?\\/{}]";  

I’ve tried a password like “dfgbrk*“, and my code, using the above regex, allowed it.
Is this consistent with what the regex defines as acceptable, or is it a problem with my code?

Can you give me an example of a string that validation using the above regex isn’t suppose to allow?

Added: Here’s how the original code uses this regex (and it works there):

public static bool ValidateTextExp(string regexp, string sText)
            {
                if ( sText == null)
                {
                    Log.WriteWarning("ValidateTextExp got null text to validate against regExp {0} . returning false",regexp);
                    return false;
                }

                return (!Regex.IsMatch(sText, regexp));
            }

It seems I’m doing something wrong..

Thanks.

  • 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-17T17:42:02+00:00Added an answer on May 17, 2026 at 5:42 pm

    Your regex matches a value that contains any single character which is not in that list.

    Your test value matches because it has spaces in it, which do not appear to be in your expression.

    The reason it’s not is because your character class starts with ^. The reason it matches any value that contains any single character that is not that is because you did not specify the beginning or end of the string, or any quantifiers.

    The above assumes I’m not missing the importance of any of the characters in the middle of the character soup 🙂

    This answer is also dependent on how you actually use the Regex in code.


    If your intention was for that Regex string to represent the only characters that are actually allowed in a password, you would change the regex like so:

    string pattern = "^[A-Z0-9...etc...]+$";
    

    The important parts there are:

    • The ^ has been removed from inside the bracket, to outside; where it signifies the start of the whole string.
    • The $ has been added to the end, where it signifies the end of the whole string.
    • Those are needed because otherwise, your pattern will match anything that contains the valid values anywhere inside – even if invalid values are also present.
    • finally, I’ve added the + quantifier, which means you want to find any one of those valid characters, one or more times. (this regex would not permit a 0-length password)

    If you wanted to permit the ^ character also as part of the password, you would add it back in between the brackets, but just *not as the first thing right after the opening bracket [. So for example:

    string pattern = "^[A-Z0-9^...etc...]+$";
    

    The ^ has special meaning in different places at different times in Regexes.

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

Sidebar

Related Questions

I really know very little about SVN and I'm trying to learn what it's
i didn't really know how to title this question, but here's a thing that
I'm actually translating some C++ code (which I know very little about, and have
I am a tinkerer—no doubt about that. For this reason (and very little beyond
I'm new to python so I really don't know the language very well. the
All, I am very new to Windows Phone and really don't know where to
I don't really know much about sockets except how to read and write to
I don't really know much about the capability of the different OSs. However, I
I must admit that I don't really know if this is the right place
I consider myself to be quite a good programmer but I know very little

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.