<--- --------------------------------------------------------------------------------------- ---- Blog Entry: Ask Ben: Extracting Parts Of An Email Address In Javascript Author: Ben Nadel / Kinky Solutions Link: http://www.bennadel.com/index.cfm?dax=blog:207.view Date Posted: Aug 18, 2006 at 7:54 AM ---- --------------------------------------------------------------------------------------- ---> function GetEmailParts( strEmail ){ // Set up a default structure with null values // incase our email matching fails. var objParts = { user: null, domain: null, ext: null }; // Get the parts of the email address by leveraging // the String::replace method. Notice that we are // matching on the whole string using ^...$ notation. strEmail.replace( new RegExp( "^(.+)@(.+)\\.(\\w+)$" , "i" ), // Send the match to the sub-function. function( $0, $1, $2, $3 ){ objParts.user = $1; objParts.domain = $2; objParts.ext = $3; } ); // Return the "potentially" updated parts structure. return( objParts ); }