Thursday 15 November 2012

Encode Your Email Address - Anti-Spam


Encode Your Email Address - Anti-Spam


To avoid the e-mail adresses being picked-up by spam robots there are a few techniques to encode the adres. The most simple way would be using something like this:

VB


        Public Shared Function EncodeMailAdress(ByVal value As String) As String
            Dim sb As New System.Text.StringBuilder(value.Length * 6)
            Dim c As Char
            For Each c In value
                sb.Append("&#")
                sb.Append(Convert.ToByte(c))
                sb.Append(";")
            Next
            Return sb.ToString()
        End Function

 
 
C#



public static string EncodeMailAdress(string value)
{
 System.Text.StringBuilder sb = new System.Text.StringBuilder(value.Length * 6);
 char c = '\0';
 foreach (char c_loopVariable in value) {
  c = c_loopVariable;
  sb.Append("&#");
  sb.Append(Convert.ToByte(c));
  sb.Append(";");
 }
 return sb.ToString();
}

 
 
Design Part:


<a href='<%= EncodeMailAdress("mailto:123@abc.com")%>'>Click me</a> 
 

 
  

No comments:

Post a Comment

Thank You for Your Comments. We will get back to you soon.

back to top