I was wondering if anyone could give me the code for email validation on a textbox named, txtEmail.

I have used a validator but there is a problem with IIS7 and this so i need to code it behind the text box. I would like to inform the user that they have not entered a valid email address via a message box and not allow them to proceed until it is correct..

Can anyone help me with this??

thanks

Eric

Recommended Answers

All 6 Replies

Welcome erictheking1.

You should post your question in ASP.NET forum. Regarding to your problem you must have use javascript with RegExp (regular expression) pattern or RegularExpression Validator control.

why dont you use built-in validators in the toolbox?

Adatapost is right, that is an Asp.Net question.

Im sorry, maybe i didnt make myself clear. This is a c# question. The regular expression validators and every other validators throw an web reference error when i host the page. I have all ready researched this problem and microsoft are currently trying to find a solution. It has to do with IIS 7. (asp.net problem)

The question im asking is can anyone give me c# code that i can put behind a button so that the textbox must be in email address format before the user can proceed. An if statement or something equivalant.

Thanks

Eric

You want to perform the validation server side in c# code behind right? Here is how I do it:

public static bool IsValidEmailAddr(string email)
    {
      try
      {
        System.Net.Mail.MailAddress addr = new System.Net.Mail.MailAddress(email);
      }
      catch
      {
        return false;
      }
      return true;
    }
commented: Deep respect... +6
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.