Validate an Email Address
9
mattrmiller
Fixed the regular expression to check for more strict requirements.
//Set the email pattern string
Pattern pPattern = Pattern.compile("([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(" + "([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)");
//Match the given string with the pattern
Matcher mMather = pPattern.matcher(strEmail);
return mMather.matches();






It's take from: http://svn.sourceforge.net/viewvc/wicket/trunk/wicket-extensions/src/java/wicket/validation/validator/RfcCompliantEmailAddressPatternValidator.java?view=markup
As the javadoc says, you really should use this, but it's interesting to look at... it's almost like one of those blurry pictures that stare at until you see the hidden image.
This throws an exception if the address is invalid
But this way is good for a "quick n dirty" test