Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
using regex for avoid some special characters in textbox.

What I have tried:

using regex for this one but how to allow particular special character,letters,numbers?
Posted
Updated 28-Sep-16 3:20am
v2
Comments
Suvendu Shekhar Giri 28-Sep-16 7:19am    
Share what have you tried so far.
Raja Ganapathy 28-Sep-16 8:26am    
if (Regex.IsMatch(text, @"^[a-zA-Z0-9_]+$"))
{
Master.ShowMessage("Enter number correctly", MessageHelper.MessageType.Information);
}

Depends on your existing Regex.
For example:
^\d+$
Would allow only numbers.
^[-+]?\d+(\.\d+)?$
Would allow numbers with a decimal point, and an optional leading plus or minus.
To allow or disallow specific characters, we'd need to know what you want to permit - but get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.
It'll help you design your own to fit your specific needs.
 
Share this answer
 
Comments
W Balboos, GHB 28-Sep-16 8:06am    
Thanks for Expresso link - I'll be looking into that.
OriginalGriff 28-Sep-16 8:22am    
It's a good 'un - I've been using it for a couple of years, and it makes life a whole load easier. It even generates C# / VB code you can copy'n'paste right into your app.

I wish I'd written it! :laugh:
Something that will help you in general is to learn more about how to use RegEx. A very helpful site is regexlib[^] they have a large library of Regular Expressions. They also have a RegEx tester[^] which is very helpful in testing your RegEx code. Also, as Griff said, Ultrapico's Expresso[^] is a very useful tool for creating regular expressions.
 
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