Validate an Email Address





9
Date Submitted Fri. May. 26th, 2006 11:16 AM
Revision 2 of 2
Coder mattrmiller
Tags "Email Address" | Java | String | Validate
Comments 2 comments
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();

 

Matthew R. Miller

www.bluecreststudios.com
=================
Matthew R. Miller

http://bluecreststudios.com
http://www.codeandcoffee.com

Comments

Comments RFC 882 Compliant REGEX
Sun. Oct. 8th, 2006 11:51 AM    Newbie Caleb
Comments A better method
Mon. Feb. 20th, 2006 6:19 AM    Scripter TimYates

Voting