question

KeithCrotty-5608 avatar image
0 Votes"
KeithCrotty-5608 asked ·

Regex question

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 = @"(?//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?

not-supported
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JoffreyNURIT-4769 avatar image
0 Votes"
JoffreyNURIT-4769 answered ·

Hi @KeithCrotty-5608

The regex for your need is:

@"^[\w\ -]*$"

If this does not cover all your cases, please send them to us.

Best regards, Joffrey

· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DSPatrick avatar image
0 Votes"
DSPatrick answered ·

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

· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.