Solved

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

Posted on 2012-03-23
1
454 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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…

771 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

15 Experts available now in Live!

Get 1:1 Help Now