Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine an alphabetic character that is not uppercase or lowercase

Tags:

c#

.net

Microsoft uses this rule as one of its complexity rules:

Any Unicode character that is categorized as an alphabetic character but is not uppercase or lowercase. This includes Unicode characters from Asian languages.

Testing for usual rules, like uppercase can be as simple as password.Any(char.IsUpper).

What test could I use in C# to test for alphabetic Unicode characters that are not uppercase or lowercase?

like image 389
Reuben Avatar asked Aug 12 '14 04:08

Reuben


2 Answers

How about the literal translation of the rule:

password.Any(c => Char.IsLetter(c) &&
                  !Char.IsUpper(c) &&
                  !Char.IsLower(c))
like image 106
metacubed Avatar answered Sep 23 '22 18:09

metacubed


When you convert ascii a and A to unicode, you'll get a and A so obviously, they are not the same.


Update: Here's an example of what I think you're asking:

var c = 'א';
c.Dump();
char.IsUpper(c).Dump("is upper");    // False
char.IsLower(c).Dump("is lower");    // False
char.IsLetterOrDigit(c).Dump("is letter or digit"); // True
char.IsNumber(c).Dump("is Number");  // False
like image 40
Noctis Avatar answered Sep 23 '22 18:09

Noctis