.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Regex : Email or Url

Posted By:      Posted Date: September 17, 2010    Points: 0   Category :ASP.Net
hi allI have a text field where user can enter either an URL or an Email address. How can I use a RegularExpressionValidator to validate that user have entered an URL or an Email addressthanks in advanceRegards

View Complete Post

More Related Resource Links

Best regex for email body on contact form?

I'm not sure the best way to do a regex for the body section of an email contact form.  I want to use the regex to prevent more than 150 characters from being entered.  I assume this is sufficient, I may need more.  I also want it to help guard against sql injection attacks. The more I think about it the more characters I can think of that should be allowed.  I want to allow punctuation since it's for an email and people should be using full sentences.  These are some other things that make sense to allow: " , ', : , ; , $ , . , ! , ? , - , _ , @ , & , ( , ). They cover situations when someone may put an email address or phone number in the body section for the email.  I also want to allow letters and numbers.    I'm not sure if it's best to allow the characters I mentioned or not allow characters that pose a potential threat.  I think allowing the ones I want is the best way, but I'm not sure.  Can someone please give an example and/or suggestions?  Are there other characters that should be allowed?  I don't have much yet: "^(?i)[a-z0-9\s]{1,150}$"

email Regex


I am trying of do a regex validation on a email but its not really working. 

I think it has more to do with defining the reg-ex 

My code 

function isValidEmail(myEmail) {
	var isValidE;
	var regEx;
	isValidE = True;
	var regEx = New RegExp;
	regEx.IgnoreCase = False;
	regEx.Pattern = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$";
	isValidE = regEx.Test(myEmail);
	isValidEmail = isValidE;


Microsoft JScript compilation error '800a03ec'

Expected ';'

/app/test/mail2.asp, line 7

var regEx = New RegExp;

Thanks for all the help

RegEx: converting email address to mailto link in a string using VB



i have tried various ways to accomplish this, but to no avail.  I don't know how to generate the replacement text (mailto link) so I just used a bunch of x's until I can figure it out.  Here is what I have (which currently not replacing emails in string):

Here is my Code behind:

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load


            Me.lblText.Text = DAL.PortLog.PortLogs.PortLogToHTML(Me.TransitID)
        End Sub

Here is the called function to replace email addresses:

    Public Shared Function ConvertEmailToMailToLinks(ByVal textToConvert As String) As String

        Dim pattern As String = "\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b"
        Dim input As String = textToconvert
        Dim replacement As String = "xxxxxxxxxXXXXxxxxx"  'test
        Dim rgx As New Regex(pattern)
        Dim result As String = rgx.Replace(input, replacement)

        Return result

    End Function

Here is the DAL code:

PrintPocketCE Print Pocket Excel, Pocket Word and email files

Version 3.560 (May 15, 2009):

Important bug fix: a slight difference in how some devices create fonts was causing a few devices to have significantly longer print times for large print jobs.

Adjusted PocketJet printer paper feed commands

Other minor fixes and enhancements.

Version 3.559 (Mar 5, 2009):

Added support for Martel MCP78xx printers

Version 3.558 (Aug 20, 2008):

Added support for Martel MCP78xx printers

Version 3.557 (June 27, 2008):

Fixed error in Canon printer support

Fixed COM0 port selection

Version 3.556 (June 15, 2008):

Added support for Brother MW-260

Added support for Sato MB400

Version 3.555 (Aug 8, 2007):

Added support for Pentax RuggedJet 3 and RuggedJet 4 printers

Changed Epson TM-P60 support to maximum page width of 1200 dots

Version 3.551 (Aug 1, 2006):

Added Peripheral Nomad printer support

Version 3.550 (Mar 23, 2006):

Added Panasonic JT-H200PR printer support

Added Pocket Spectrum printer support

Fixed problem with WM5.0 "inverted image" problem

Send Email from SQL Server Express Using a CLR Stored Procedure

One of the nice things about SQL Server is the ability to send email using T-SQL. The downside is that this functionality does not exist in SQL Server Express. In this tip I will show you how to build a basic CLR stored procedure to send email messages from SQL Server Express, although this same technique could be used for any version of SQL Server.

If you have not yet built a CLR stored procedure, please refer to this tip for what needs to be done for the initial setup.

Sending a File Using Email Helper in WebPages/Razor


Note: This is particularly with respect to Email Helper in WebPages/Razor. Please don't post links using System.Net.Mail object.

Following this tutorial: http://www.asp.net/webmatrix/tutorials/9-adding-email-to-your-website

Under "Sending a File Using Email" section what exactly is the code trying to do.

1: The SendFile.cshtml does not have any option to select file.

2: ProcessFile.cshtml is running fine. I am getting the email but no attachement.

I tried changing fileAttachment input to type="file" but not file is being sent to my email. I just get the message send in body.

Question: How exactly this file attachment works using Email Helper in WebPages.

Linq - add data to database then email user the details


Hi all

I'm not sure how to structure the code for this but what I want to do is be able to add data to a database, and once this has completed successfully, then email the user to say the details have been added successfully to the database.

I need to:

1. Check that the relevant data has been added into the database then

2. Email the details of the relevant data when completed. 


Thanks in advance for your help,




Using CreateNewUserWizard SendingMail method to email me, not applicatnt.


I have staff area of my site I am protecting with forms authentication using c# and .Net 4.0. What I want to do is let the staff members register on the site but instead of the confermation email being sent to them I want it sent to me so I can go in and approve it. I have been trying to use the SendingMail method  but can not figure out how to get it to email me instead of the person that registered. I have searched around this site and find many topics on the SendingMail method but none seem to properly address my issue. Can anyone help me out?

How to send an email with information in query string


First I will say I googled (Binged to make Bill happy) for this but could not find anything, perhaps I am not stating what I need correctly;

I have a website that a customer creates orders (for a printing company) and after the order, I would like to email the customer a link to view the status of their order;

I need to send the CustomerID in the link so on the returning page if a CustomerID is detected in the querystring, I "auto login" the client and open the "Dashboard" for the order page for that customer.

Can anyone point me in the right direction as to how to send the link and how to parse the querystring to get the values from the link;

Thank you if you can point me in the right direction.

Fetching the Currently Logged in user Email


Hey Frnds,

I am using the System.DirectoryServices.UserPrincipal.Current.EmailAddress to fetch the Currently logged in users email from AD.

If  debug my sol am getting the Exact mail id of that Particular user for ex:john@in.domain.com.

If i host My Application on iis

And Access my App am getting some other Email id instead of the john@in.domain.com.

I have changed the Application Pool identity to NetWorkService.

Can any one tell what could be wrong




email notification error 5.1.1


 I am getting an error when sending email via asp.net.  The error is "Mailbox unavailable. The server response was: 5.1.1...User unknown."

However, the email is getting sent.  Why is asp.net returning this error?

I'm using VS 2008, vb.net,  running 2.0 framework.  This happens regardless of whether I'm testing my application from my local machine or running production version.  Also, I can send a batch of emails and get the error for some but not all.

I would like to be able to count of the error messages really being accurate, so this situation is unhelpful to our users, because they will start to just ignore all error messages.




Regex pattern for validating IPv6


Can anyone can make a regular expression pattern for validating IPv6 (not IPv4)?

Ipv6 has many formats and aliases. I tried making the pattern but written in a lot of codes (i'm not sure my code below will be 100% accepting valid formats and 100% declines invalid formats).


Email Help (System.Net.Mail)


Hi I have a annoying problem. 
I have created a page which takes users details for a quote.

I have then created the form to be emailed to both the user and myself. (Which works fine ATM)

However I would also like to be able to attach a file containing terms and conditions to the email.

I have tried doing this using 

EmailMsg.Attachments.Add(new Attachment("C:\\attachme.txt"));

But everytime that line of code is hit it fails and is caught by my try catch.

Take that line out and the email sends fine, put it in and it breaks the whole page.

Am I missing something really obvious?

System.Threading AND email


Hi guys,

I really need some help (and also some code example), in how to use System.Threading to send emails.

The issue is:

a) I have a function that sends emails;

b) But I don't want to keep the customers waiting for the email being sent;

c) so, I figure it out that the System.Threading is the best way to do that; But I don't know how exactly I cant use it.

PLEASE, i'm VB - not C# - developer, and I really appreciate help in that language.

I can't use Windows Services or SQL Jobs...

Could you help me on this?



Send email throught proxy



i want to send a mail via my mvc application hosted by cassini ,but  i access to the internet connexion throught proxy

i add this lines on my web config :

    <defaultProxy  enabled="true" >
      <proxy proxyaddress=""/>
        <network />
and in my code i have :
 MailMessage mail = new MailMessage();
             mail.From = new MailAddress("yyy@xxx.fr");
                    mail.Subject = "Test";

                    string Body = "Hi, this mail is to test sending mail" 
                    mail.Body = Body;
                    mail.IsBodyHtml = true;
                    SmtpClient smtp = new SmtpClient("");
                    smtp.Port = 25;

                catch (Exception ex)
                    string exep = "Send Email Failed." + ex.Message;

 i have un exception :"Unable to connect to the remote server"

getting a email delivert status when sending email using msdb.dbo.sp_send_dbmail


Hi All,

Can some help me regarding following.

I have set a job in sql server 2008 to send reminder emails for product expiration.
Now I want a report which will specify the list of the emails sent with the email status details like queued ,sent,delivered, failed.

I can fetch the emails that are sent by querying the like following

select * from sysmail_mailitems SM inner join sysmail_profile SP on SM.Profile_Id = SP.Profile_Id
and SP.Name ='ReminderProfile'

The problem is only getting a perfect status of email whether it is delived or failed. How I can get those status ?
Please help.


Email this Post in SharePoint Blog is not working for Lotus Notes 6.5


I have tried "Email this Post" in a SharePoint blog. I got the email as desired, but the doesnot resolve the post.

Here are the link examples:

I got the link in email as mentioned below:


But i should get as below to resolve the link:


Any ideas?


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend