0

how to give email validation to textbox in gridview in asp.net

I Have gridview and in that i have textbox for email and i want to give email validation to that textbox on save

Amol Khairnar
  • 59
  • 1
  • 7

1 Answers1

1

Regex sample

bool isEmail = Regex.IsMatch(emailString, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);

or

.Net.Mail sample

bool IsValidEmail(string email)
{
    try {
        var mail = new System.Net.Mail.MailAddress(email);
        return true;
    }
    catch {
        return false;
    }
}
Mert
  • 6,140
  • 6
  • 30
  • 61