C# character non alfa numeric check contain

Try this one:

public static Boolean isAlphaNumeric(string strToCheck){
Regex rg =new Regex(@"^[a-zA-Z0-9\s,]*$");
return rg.IsMatch(strToCheck);
}

It’s more undestandable, if you specify in regex, what your string SHOULD contain, and not what it MUST NOT.

In the example above:

^ – means start of the string
[]* – could contain any number of characters between brackets
a-zA-Z0-9 – any alphanumeric characters
\s – any space characters (space/tab/etc.)
, – commas
$ – end of the string

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: