views:

223

answers:

3

Almost everyone needs simple types such as these (tel. number, credit card, uri, email address) - is there a C# library available to save everyone having to re-invent the wheel?

+1  A: 

You should look into regular expressions (System.Text.RegularExpressions in VB--I'm sure it is the same for C#) for validating these types. For credit card validations, look into Luhn's algorithm.

Kyle
I don't think the OP is looking just for validation routines but rather classes that model those real-world objects as datatypes.
Scott Dorman
and remember, if you have a problem and you think, "i can solve this with a regular expression," then now you have two problems ;-)
Steven A. Lowe
A: 

Reinventing the wheel makes you a better programmer.

alord1689
+1  A: 

I don't know of one off-hand, but I'm sure one exists. I'm also equally sure that it is woefully inadequate when it comes to localization issues. The reason why things like addresses and phone numbers keep getting re-invented is that there's no global standard in how to deal with them.

You might even be able to come up with a reasonably generic International Address object, for example, but which fields and methods that people are going to use on that object are going to vary so greatly that it's almost not worth it.

For example, if I'm just storing addresses for a mailing list in the US, I have a street, city, state, and zip code. I'm not going to need the country field. The company next door might be running a global shipping business and need to deal not only with country codes, but with addresses in small countries that don't bother with postal codes or street addresses, because if you know the person's name and the town, that's all you need.

This is why there are so many home-grown objects for addresses and phone numbers. It's usually easier to just write a library that fits your needs than to fight with somebody else's ideas on what an address should be.

Jeromy Irvine