try this
bool IsValidEmail(string email)
{
try {
var mail = new System.Net.Mail.MailAddress(email);
return true;
}
catch {
return false;
}
}
Frage
Does anyone have a ready email mask for MaskedTextBox?
e.g.
aaaa...aaa@fff.ee / aaaa...aaa@ff.ee / aaaa...aaa@fff.eee / aaaa...aaa@ff.eee /
p.s. Please do not suggest RegEx!
Lösung
try this
bool IsValidEmail(string email)
{
try {
var mail = new System.Net.Mail.MailAddress(email);
return true;
}
catch {
return false;
}
}
Andere Tipps
Try this code:
<asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
<cc1:MaskedEditExtender ID="MaskedEditExtender1" runat="server" Mask="AAAAAA@domain.com"
InputDirection="LeftToRight" TargetControlID="txtemail">
</cc1:MaskedEditExtender>
In mask property in place of AAAAAA
you want add more AAA
it's depend on your requiredment how much character
to allow user to enterde.
OR
you have put like this option in textbox user can enter only character
whatever you pass in mask property.
Like Below Image:
http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.mask(v=vs.90).aspxMaskedTextBox
public static bool IsValidEmail(string email)
{
if (string.IsNullOrWhiteSpace(email))
return false;
try
{
// Normalize the domain
email = Regex.Replace(email, @"(@)(.+)$", DomainMapper,
RegexOptions.None, TimeSpan.FromMilliseconds(200));
// Examines the domain part of the email and normalizes it.
string DomainMapper(Match match)
{
// Use IdnMapping class to convert Unicode domain names.
var idn = new IdnMapping();
// Pull out and process domain name (throws ArgumentException on invalid)
string domainName = idn.GetAscii(match.Groups[2].Value);
return match.Groups[1].Value + domainName;
}
}
catch (RegexMatchTimeoutException e)
{
return false;
}
catch (ArgumentException e)
{
return false;
}
try
{
return Regex.IsMatch(email,@"^[^@\s]+@[^@\s]+\.[^@\s]+$", RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250));
}
catch (RegexMatchTimeoutException)
{
return false;
}
}