Solved

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

Posted on 2012-03-23
1
490 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

751 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