Saturday, May 17, 2008

WPF Zip Code ValidationRule

I am working on validation for a WPF application and here is my class to validate American Zip Codes.

class ZipCodeRule : ValidationRule
{
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
ErrorMessage errMessage = new ErrorMessage();
Docs.App_Code.Validation validationHelper = new Docs.App_Code.Validation();
try
{
string currentValue = (string)value;
if (currentValue.Length == 5)
{
if (validationHelper.IsNumeric(currentValue))
{
return ValidationResult.ValidResult;
}
}
else if (currentValue.Length == 9)
{
if (validationHelper.IsNumeric(currentValue))
{
return ValidationResult.ValidResult;
}
}
else if (currentValue.Length == 10)
{
string firstFive = currentValue.Substring(0, 5);
string lastFour = currentValue.Substring(6, 4);
if (validationHelper.IsNumeric(firstFive)) {
if (validationHelper.IsNumeric(lastFour)) {
if (currentValue.Substring(5,1) == "-") {
return ValidationResult.ValidResult;
}
}
}
}
else if (currentValue.Length == 0)
{
return ValidationResult.ValidResult;
}
return new ValidationResult(false, errMessage.getErrorMessage(1005));
}
catch (FormatException)
{
return new ValidationResult(false, errMessage.getErrorMessage(1005));
}
}
}

Friday, May 2, 2008

CSS Stylesheet Frameworks

Based in part by Paul Spencer.

As Web Developors we are usually in the business of designing web pages that contains all kinds of content. While limiting myself to plain HTML tags and avoiding any kind of color/style decisions is usually a wise idea, sometimes its nice to put some effort into the web page beyond the absolute minimum.

For those of us that are, um, designed-challenged, using a CSS framework is a great place to start. Paul recently found a couple of them that might be of interest:

http://code.google.com/p/blueprintcss/

"Blueprint is a CSS framework, which aims to cut down on your CSS development time. It gives you a solid CSS foundation to build your project on top of, with an easy-to-use grid, sensible typography, and even a stylesheet for printing."

http://960.gs/

"The 960 Grid System is an effort to streamline web development workflow by providing commonly used dimensions, based on a width of 960 pixels. There are two variants: 12 and 16 columns, which can be used separately or in tandem."

Both frameworks provide a fixed column grid based on a fixed width of 960 pixels, and blueprint adds some decent choices for colors, styles etc.

Paul put together a simple (non-mapping) page using blueprint after about 5 mins of reading the tutorial and was pretty happy with the result.

I haven't tried 960.gs yet but it seems similar in concept and probably more appropriate if you just want the layout part.

I haven't researched other CSS frameworks so there's probably something better out there if you care to look.