Reuben
Reuben

Reputation: 4266

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

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?

Upvotes: 7

Views: 5035

Answers (2)

Noctis
Noctis

Reputation: 11763

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

Upvotes: 1

metacubed
metacubed

Reputation: 7271

How about the literal translation of the rule:

password.Any(c => Char.IsLetter(c) &&
                  !Char.IsUpper(c) &&
                  !Char.IsLower(c))

Upvotes: 8

Related Questions