I have a textbox named "txt_contact". User fills his contact including his email id, for example:
Contact: Reggie Frederick, Email: regtnt@rediffmail.com; Mob: +91 984 807 7749
I am saving this information in the database. But I want "regtnt@rediffmail.com" as an anchor tag and when clicked, it should redirect to rediffmail.com. What can be done to achieve this??
This is what I have already tried.
string cont = txt_contact.Text;
Regex regx1 = new Regex("http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?", RegexOptions.IgnoreCase);
MatchCollection matches = regx1.Matches(cont);
foreach (Match match in matches)
{
cont = cont.Replace(match.Value, "<a class='abc' href='" + match.Value + "'>" + match.Value + "</a>");
}
NOTE: User can fill any email account in the textbox (gmail, yahoo etc)
This helped me:
When I show data, I am writing a regular expression for Email.
$(document).ready(function () {
var regEx = /(\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)/;
var contact = $("span[id*=lblContact]")
$(contact).filter(function () {
return $(this).html().match(regEx);
}).each(function () {
$(this).html($(this).html().replace(regEx, "<a style=color:blue href=\"mailto:$1\">$1</a>"));
});
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.