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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:57:45+00:00 2026-06-13T21:57:45+00:00

Im checking some strings with my regex and somehow its not perfect. Im not

  • 0

Im checking some strings with my regex and somehow its not perfect. Im not sure why. I would like to allow string with only these characters:

  • A to Z
  • 0 to 9
  • .
  • %
  • /
  • {space}
  • +
  • $

So I thought this regex should be enough:

Regex("[^A-Z0-9.$/+%\\- ]$")

But with some string its not really working. I made a small example:

    static Regex regex = new Regex("[^A-Z0-9.$/+%\\- ]$");

    static void Main()
    {
        string s;

        Console.WriteLine("check: \n");

        s = "?~=) 2313";
        Console.WriteLine(s + ": " +IsValid(s));

        s = "ÄÜÖ";
        Console.WriteLine(s + ": " + IsValid(s));

        s = "Ü~=) 2313";
        Console.WriteLine(s + ": " + IsValid(s));

        s = "Ü 2313";
        Console.WriteLine(s + ": " + IsValid(s));

        s = "~=) 2313 Ü";
        Console.WriteLine(s + ": " + IsValid(s));

        s = "ÜÜÜ";
        Console.WriteLine(s + ": " + IsValid(s));

        s = "~=)";
        Console.WriteLine(s + ": " + IsValid(s));

        s = "THIS--STRING $1234567890$ SHOULD BE VALID.%/ +";
        Console.WriteLine(s + ": " + IsValid(s));

        Console.ReadKey();
    }

    public static bool IsValid(string input)
    {
        if (regex.IsMatch(input)) return false;
        return true;
    }

As output I get:

enter image description here

The 1.,3. and 4. are True, but this is wrong. What is wrong with my regex? Any ideas? Thank you

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

    It should be

    ^[A-Z0-9.$/+%\\- ]+$
    |                 ||match end of the string
    |                 |
    |                 |match one or more characters of [A-Z0-9.$/+%\\- ]
    |start of the string
    

    You need to use quantifiers like +,* to match multiple characters


    Your IsValid Class should be

    public static bool IsValid(string input)
        {
            if (regex.IsMatch(input)) return true;
            return false;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to know the possible Regex suitable for checking a string that includes
x = ['Some strings.', 1, 2, 3, 'More strings!', 'Fanc\xc3\xbf string!'] y = [i.decode('UTF-8')
I would like to programmatically check whether a string can be pronounced or needs
What is the best way for checking empty strings (I'm not asking about initializing!
I'm sure I'm contravening some deep dark law of javascript, but I'm not really
Pretty simple question. I have a few ASP RequiredFieldValdators checking some text boxes. Out
I'm checking out some PHP 5.3.0 features and ran across some code on the
I have been checking out some of the possible timers lately, and System.Threading.Timer and
I was checking out some of Amazon 's CSS and noticed they have HTML
I'm writing some error checking and trying to make use of an boolean array

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.