Last active
December 24, 2015 08:59
-
-
Save juanbrujo/6773848 to your computer and use it in GitHub Desktop.
Find emails inside a string and transforms them in clickable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(".real-content") | |
.find (':contains("@")') | |
.each (function (index, element) { | |
var emailPattern = /[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/; | |
var corrected = $(element).html(); | |
var remainder = corrected; | |
while ( emailPattern.test (remainder)) { | |
var email = emailPattern.exec (remainder); | |
remainder = remainder.replace (email, ''); | |
corrected = corrected.replace (email, '<a href="mailto:' + email + '">' + email + '</a>'); | |
} | |
$(element).html(corrected); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment