PDA

View Full Version : Regular Expressions to test Email Addresses


Whitesword
07-27-2003, 11:26 AM
I got this one off Regular Expressions Library (http://regexlib.com) as I had a few problems with the one posted earlier. I live in New Zealand and there were a few quirks that the earlier one did not check for.

This one was posted on the above site and is now the definitive one that I use. It also checks for IP addresses, .com, .edu, .gov, .mil, .org; .com.<country>, .co.<country>, .edu.<country>, .mil.<country>, .org.<country>, .gov.<country> and several other permuations.


"^([a-zA-Z0-9_\-])+(\.([a-zA-Z0-9_\-])+)*@((\[(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))\]))|((([a-zA-Z0-9])+(([\-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([\-])+([a-zA-Z0-9])+)*))$"


I strongly advise you to check the above link for any updates. They have been very thorough on this one as it appears that it is quite a common problem among web site developers.

Oh yes, I almost forgot... this will work with any regular expression object, whether it be VB's RegExp object or the many used in the linux platform.

Cheers

Whitesword