In this article I’ll cover two useful regular expressions that often come in handy when writing validation logic for a Web page. Most programmers will find they need to either validate a URL or an Email at some point, and the example expressions below are the most commonly used versions of each expression.
I’m not sure who originally created each of these expressions, so I have no idea who I can give the credit for these to, but they have helped me often. Bottom line for these two examples is that I like to use the example expressions found in an article on NetTuts+/regular-expressions.info and modify them to meet my needs.
Since I’m mentioning the regular-expressions.info site, I definitely suggest browsing over to it if you are looking for further reading about regular expressions including sample code and reference material.
Also, have a look at a free online regular expression tool by Derek Slager. You can use this tool to test your regular expressions if you don’t have a program on your computer to do so. I have spent quite some time trying to find a good online regular expression testing tool, but every one I have found is either too expensive, or full of advertising, so this tool is definitely worth checking out.