Posts

Showing posts from October, 2008

Regular Expressions in C# - Password Validator Revisited

Sometimes we make life more difficult than it needs to be. Lately, I've learned a little more about Regular Expressions and "Negative Look-Around". I've used it a lot, but it only recently dawned upon me that I was not making full use of it. Case in point, take a look at my earlier regular expression article where I explain how to validate a password with multiple requirements ( Regular Expression Alternations ). This article discusses the absense of the boolean AND in regular expressions and provides a complex IF-THEN-ELSE approach to test a string for conforming to multiple "password" constraints. And my subsequent article ( Regular Expression Double Negatives ) gets more complex with an "inside-out" approach to compensate for the lack of an AND operator. But, let's go back even further to the article where I "explain" Negative Look-ahead . In this article, I provide the simple Negative Look-ahead pattern... “(?!pattern)” ....

Callbacks And Delegates

It's been a couple of weeks since last writing. Besides being very busy, I've had a touch of "writer's block". Nothing too serious, I should get over it soon. Lately, I've been intrigued by the abundant use of callback functions and delegates in the .NET Framework. If you want to do anything interesting, you gotta know callbacks. I'll try to describe callbacks and delegates in simplistic terms. Maybe it will help you over the hump. Consider the following code... List list = new List (); //Populate list with some MyClass objects for(int i=0; i list.Add(new MyClass(){ ID=i, strValue=i.ToString() }); //Sort the list list.Sort(); foreach(MyClass c in list) Console.WriteLine("{0}",c.strValue); ... public class MyClass { public int ID; public string strValue; public override string ToString() { return strValue; } } This code throws an exception at the line that says S...