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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:32:09+00:00 2026-05-31T13:32:09+00:00

I am trying to validate a string based on the inputed characters. I want

  • 0

I am trying to validate a string based on the inputed characters. I want to be able to set which characters are allowed besides characters and numbers. Below is my extension method:

public static bool isAlphaNumeric(this string inputString, string allowedChars)
{
    StringBuilder str = new StringBuilder(allowedChars);
    str.Replace(" ", "\\s");
    str.Replace("\n","\\\\");
    str.Replace("/n", "////");
    allowedChars = str.ToString();

    Regex rg = new Regex(@"^[a-zA-Z0-9" + allowedChars + "]*$");
    return rg.IsMatch(inputString);
}

The way I use this is:

s string = " te\m@as 1963' yili.ışçöÖÇÜ/nda olbnrdu" // just a test string with no meaning
if (s.isAlphaNumeric("ışŞö\Ö@üÜçÇ ğ'Ğ/.")) {...}

Of course it gives an error:

parsing "^[a-zA-Z0-9ışŞö\Ö@üÜçÇ\sğ'Ğ/.]*$" - Unrecognized escape sequence

the stringbuilder replace function is wrong which I am aware of. I want to be able to accept all characters given in the allowedChars parameter. This can also include slashes (any other characters similar to slashes I am not aware of?) Given this, how can I get my replace function work? and also is the way I am doing is correct? I am very very new to regular expressions and have no clue on how to work with them…

  • 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-31T13:32:10+00:00Added an answer on May 31, 2026 at 1:32 pm

    You need to use Regex.Escape on your string.

    allowedChars = Regex.Escape(str.ToString());
    

    ought to do it.

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

Sidebar

Related Questions

I'm trying to validate user input, which is just comma separated numbers. I'd like
I am trying to validate a string of 3 numbers followed by / then
I am trying to validate an input string (which can be copied & pasted
I'm trying to write a a regex to validate a string to match the
I've been trying to validate an inputted string ( sys argv[1] in this case).
I have a CSV string that I am trying to validate via regex to
I am trying to validate a string as a phone number (digits and certain
I am trying to validate my string with the regular expression. Here is what
I am trying to programatically validate a user login/pass using Spring Security, so I
When trying to validate my site, I get the following error: Line 188, column

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.