Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I want to validate alphanumeric special characters in asp.net with c#. I have set the characters in the web.config file as a key under appsettings. But I am getting exception

What I have tried:

Code is as below:
I am getting exception while setting the alphanumeric special characters in config file as below
Under appsettings
add key="BlockedSpCharacters" value="^[a-zA-Z0-9\s.>
Posted
Updated 16-Mar-22 9:53am
Comments
Richard Deeming 16-Mar-22 10:56am    
There's a secret error somewhere in your secret code. You need to fix that.

Seriously, how do you expect anyone to be able to help you fix an error we can't see in code we can't see, when you haven't even provided a single valid line from your source or config file?

Click the green "Improve question" link and update your question. Add the complete line from your config file, the relevant parts of your code, and the full details of the error you are getting.

1 solution

As the config file is probably in XML format, you need to escape special characters.
You can find a nice routine here: Returning an XML Encoded String in .NET - Rick Strahl's Web Log[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900