DotNet Mirror
  DNM facebook   DNM Google+   DNM Twitter   

parse an email address text before @ symbol in javascript

By Ashok Nalam on 28 Feb 2013 | Category: JavaScript & Jquery | Tagged: string 
  Discuss Add Comment   |  
Add rating Rate this resource   
Inorder to get the email address text before "@" in javascript use the below code.
emailAdr.substring(0, emailAdr.indexOf("@"))

Example

<html>
<script type="text/javascript" language="javascript">
var emailSubStrBeforeAtSymbol = ''
function GetEmailSubStringBeforeAtSymbol(emailAdr) {
emailSubStrBeforeAtSymbol = '';
if(emailAdr.indexOf("@") != -1)
{
emailSubStrBeforeAtSymbol = emailAdr.substring(0, emailAdr.indexOf("@"));
}
}
GetEmailSubStringBeforeAtSymbol('dotnetmirror@sampledomain.com')
alert(emailSubStrBeforeAtSymbol);
GetEmailSubStringBeforeAtSymbol('invalidemail');
alert(emailSubStrBeforeAtSymbol);
</script>
<body>Get the text before "@" in javascript </body>
</html>

output:

dotnetmirror (dotnetmirror@sampledomain.com)
'' (invalidemail)

  Discuss Add Comment    
Add rating Rate this resource   
About the Contributor
Member Since : 10 Dec 2012
Member Points (Level) : 9226  (Professional)
Location : INDIA
Home Page : http://dotnetmirror.com
About : I am admin of this site.
Rate this resource
 
Add your Comment
Name Email WebSite
Captcha Refresh


Comments (0)
No comments found, click here to add comment.
 
cheap jordans|wholesale air max|wholesale jordans|wholesale jewelry|wholesale jerseys