---
title: "The specified string is not in the form required for an e-mail address"  
description: "The specified string is not in the form required for an e-mail address"  
author: "Anonymous User"  
published: 2014-08-26  
updated: 2014-08-26  
canonical: https://www.mindstick.com/forum/2146/the-specified-string-is-not-in-the-form-required-for-an-e-mail-address  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 1 minute  

---

# The specified string is not in the form required for an e-mail address

The specified [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) is not in the [form](https://www.mindstick.com/forum/6/multi-form-mfc-application) [required](https://www.mindstick.com/forum/160269/what-is-required-data-annotation-how-does-it-affect-model-validation) for an e-mail address. Description: An unhandled [exception](https://www.mindstick.com/articles/1824/objective-c-exception-handling) occurred during the [execution](https://www.mindstick.com/blog/178/synchronous-and-asynchronous-command-execution-in-c-sharp-dot-net) of the current [web](https://www.mindstick.com/articles/12783/the-ultimate-bunch-of-free-web-design-resources) request. Please [review](https://www.mindstick.com/blog/11978/mobvoi-tichome-mini-speaker-review-discount-code-design-features-and-performance) the [stack](https://www.mindstick.com/blog/301746/why-is-stack-overflow-so-important-for-developers) [trace](https://www.mindstick.com/interview/1075/why-are-there-five-tracing-levels-in-system-diagnostics-traceswitcher) for more information about the [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) and where it originated in the code.

Exception Details: System.FormatException: The specified string is not in the form required for an e-mail address.

## Replies

### Reply by Sumit Kesarwani

Hi Pravesh,

The specified string is not in the form required for an e-mail address

The problematic code was as follows:

MailMessage objMsg = new MailMessage(regEmail.Text.ToString(), "me@mysite.com");

I fixed the issue by replacing that code with this:

MailMessage objMsg = new MailMessage();

objMsg.From = new MailAddress(regEmail.Text.ToString());

objMsg.To.Add(new MailAddress("me@mysite.com"));

It is also helpful to use a regular expression validator in your user control to make sure the address is valid, you can use the following code for asp:

<asp:RegularExpressionValidator ID="regex1" ControlToValidate="regEmail" ErrorMessage="Please enter a valid email address" ValidationExpression="^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$" ValidationGroup="regGroup" runat="server" Display="None" SetFocusOnError="True"></asp:RegularExpressionValidator>

Or if you'd prefer to validate the email in C#

```
public static bool IsValidEmail(String Email){    if( Email != null && Email != "" )        return Regex.IsMatch(Email, @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
);    else        return false;}
```


---

Original Source: https://www.mindstick.com/forum/2146/the-specified-string-is-not-in-the-form-required-for-an-e-mail-address

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
