Skip to content

Instantly share code, notes, and snippets.

@renatoargh
Forked from bennadel/code-1.js
Created August 5, 2014 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renatoargh/5c4125246791a8dcb5ad to your computer and use it in GitHub Desktop.
Save renatoargh/5c4125246791a8dcb5ad to your computer and use it in GitHub Desktop.
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 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment