The regex for your need is:
@"^[\w\ -]*$"
If this does not cover all your cases, please send them to us.
Best regards,
Joffrey
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am using Regex in a C# program. What I really want is an expression that will check for valid data input, letters, numbers, punctuation, space, etc. But, I am having problems getting even a simple alpha-num to work.
I defined 2 strings
const string C_RegXNumbers =
@"(?<=^| )\d+(.\d+)?(?=$| )|(?<=^| ).\d+(?=$| )"; //this works
const string C_RegXAlphaNumPlus = @"^[a-zA-Z]*$"; //this doesn't
Then in the code executing the Regex
I put QnA in the tag. I had to put something, but it would not let me put in C# or Regex. Something seems not right there.
if (Regex.IsMatch(strThisData, C_RegXNumbers)) …
if (Regex.IsMatch(strThisData, C_RegXAlphaNumPlus)) ...
The first one works
The much simpler fails no matter what I have tried (took out the digits)
The input string is "Open Screen". Originally, it had an exclamation point after, but I'm just trying to figure out what I'm doing wrong, so keeping it simple.
I have cut and pasted a bunch of examples, but they all fail.
And.. does anyone have a string to, basically, accept valid keyboard text. No weird printing chars, etc. I cant find one that works in my searches. Nums, AlphaNum, /?,.:;[]{} etc.
I put QnA into the Tag field. There is no dropdown and you can not put in C# Regex. Something not working properly?
The regex for your need is:
@"^[\w\ -]*$"
If this does not cover all your cases, please send them to us.
Best regards,
Joffrey
QnA currently only supports the products listed in right-hand pane. Better to reach out to subject matter experts in dedicated forums over here.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=netfxbcl
https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=csharpgeneral