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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:46:37+00:00 2026-05-22T12:46:37+00:00

i have a text box where the user will the url in it and

  • 0

i have a text box where the user will the url in it and submit that url (it takes that url and search in our db)

but before it hit the db i want to make sure that there is no special characters in it:

below is the regular expression i am using but still accepting the special characters

here are the special characters i am trying to avoid < > % ( ) + ; these special caracters can be at the begining or end for an example:

()+;http://www.site.com/images.jpg()

for an example for ampersand (&) i use the below reg expression but somehow it ignores the begining.

Regex re = new Regex("\\(|\\)|\\<|\\>|\\\"|\\;|\n|\r|\\`|^&|&$"); 

so before i submit the above url i want to trip all the unwanted caracters.

static String StripSpcialChar(String param)        
{             
String result = null;             
if (param != null)             
{                                 
Regex re = new Regex("\\&|\\(|\\)|\\<|\\>|\\\"|\\;|\n|\r|\\`");                 
result = re.Replace(param, "");                 
result = result.Trim();             
}             
return result;         
} 
  • 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-22T12:46:37+00:00Added an answer on May 22, 2026 at 12:46 pm

    This should cover the special characters you’ve specified and correctly strips an ampersand from the beginning or end of the string. To account for multiple ampersands at the beginning or end of the string you need to use &+, where the + matches one or more ampersand.

    string input = "&&&()+;http://www.site.com/images.jpg()&&&";
    Regex re = new Regex(@"[()<>"";+\n\r`]|^&+|&+$");
    string result = re.Replace(input, "");
    Console.WriteLine(result);
    

    Notice the use of the character class [...] which is much cleaner than multiple alternations with the pipe symbol. Within a character class there’s no need to escape the characters. If you ever plan to match a dash you should place it at the beginning or end of the group to avoid accidentally specifying a range of characters. For example [()<>"";+\n\r-].

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

Sidebar

Related Questions

I have a text box that will allow the user to enter multiple authors
I have one text box when user enter in text box and hit enter
I have a program which has a text box that the user can edit.
I have a text box in my page which the user will type something
I have an ASP.NET user control that contains a text box control and a
I have a text box that I am the user enters a Supplier Name
I have a textbox where user will enter the url of the image :
i have form where i have text box value and link (add). when user
I have a text-box into which a user can input a comment. The comment
I have a text box , and user enters text on here , I

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.