Here is a good compilation of codes doing string format validation in C#, VB.NET, Java, Javascript, PHP, Perl, Python, and Ruby. It’s a good reference page.

http://answers.oreilly.com/topic/224-how-to-search-line-by-line-with-a-regular-expression/