Solved

ASP.NET / VB: Automatically create email links from a static text

Posted on 2012-03-23
1
467 Views
Last Modified: 2012-08-13
Using ASP.NET / VB, how can I automatically create email links from a static text?

The following code works in PHP but I need it converted to ASP.NET / VB.

<?php

function emailize($text) {
  $regex = '/(\S+@\S+\.\S+)/i';
  $replace = "<a href='mailto:$1'>$1</a>";
  $result = preg_replace($regex, $replace, $text);
  return $result;
}

echo emailize ("Hello World me@example.com Test 123 xyz@example.com");

?>

Open in new window

0
Comment
Question by:hankknight
1 Comment
 
LVL 13

Accepted Solution

by:
Pryrates earned 500 total points
ID: 37760092
you an use a function like:
   Protected Function emailize(ByVal input As String) As String
        Return RegularExpressions.Regex.Replace(input, "(\S+\@\S+\.\S+)", "<a href='mailto:$1'>$1</a>")
    End Function

Open in new window


you can call it within your page like:
<%=emailize("Hello World me@example.com Test 123 xyz@example.com")%>

Open in new window


Hope that helps
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Running VB/Batch script through Group policy 30 76
Entity Framework 3 46
ASP.net VB.net Load contents of a GridView  to Excel 2 27
SQL Login 17 38
Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now