Posted By

world_eggplant on 01/14/10


Tagged

regex email javascript jquery address


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

dmistriotis


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


 / Published in: JavaScript
 

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.

  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  

You need to login to post a comment.