Extract email from bulk text (with Regular Expressions, JavaScript & jQuery)


/ Published in: JavaScript
Save to your folder(s)

Easily grabs email addresses from a bulk text (CSV and/or some other email address-filled list/db).

Example #2 takes the input (bulk text) from textarea #input and puts the clean emails in the textarea #extractedemails.


Copy this code and paste it in your HTML
  1. function extractEmails ( text ){
  2. return text.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
  3. }
  4.  
  5. // EXAMPLE #1
  6. var emails = extractEmails ( HugeListWithBulkTextIncludingEmailAddresses );
  7. document.write ( emails.join('\n') );
  8.  
  9.  
  10. // EXAMPLE #2 (jQuery)
  11. $(function(){
  12. $('#eform').submit(function(){
  13. $('#extractedemails').val( extractEmails($('#input').val() ).join('\n'));
  14. return false;
  15. });
  16. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.