Parsing an email for the text before the "@" symbol
Another possibility:
function emailUsername(emailAddress) {
return emailAddress.split('@')[0]
}
This splits the string in half at the @
symbol, creating an array with the two parts and then retrieves the first item in the array, which will be the part before the @
.
function emailUsername(emailAddress) {
return emailAddress.match(/^(.+)@/)[1];
}
Like this:
return emailAddress.substring(0, emailAddress.indexOf("@"));