Created
October 23, 2011 18:47
-
-
Save motowilliams/1307701 to your computer and use it in GitHub Desktop.
Checking-for-special-characters-using-LINQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class StringExtensions | |
{ | |
public static bool HasInvalidCharacters(this string value) | |
{ | |
//Ascii range between 32 and 127 | |
IEnumerable<int> lowRange = Enumerable.Range(0, 32); | |
IEnumerable<int> highRange = Enumerable.Range(128, 128); | |
IEnumerable<int> enumerable = value.ToCharArray().Select(x => Convert.ToInt32(((int)x).ToString())); | |
return lowRange.Intersect(enumerable).Count() != 0 || highRange.Intersect(enumerable).Count() != 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment