boolean isValidEmailAddress(str _emailAddress)
{
const str domainPattern = @"(@)(.+)$";
const str emailPattern = @"^[^@\s]+@[^@\s]+\.[^@\s]+$";
boolean isValidEmail;
if (!_emailAddress || strLen(_emailAddress) == 0)
{
isValidEmail = false;
}
else
{
try
{
// Normalize the domain
System.Text.RegularExpressions.Match domainMatch = System.Text.RegularExpressions.Regex::Match(
_emailAddress, domainPattern,
System.Text.RegularExpressions.RegexOptions::None, System.TimeSpan::FromMilliseconds(200));
if (domainMatch.get_Success())
{
// Use IdnMapping class to convert Unicode domain names.
System.Globalization.IdnMapping idn = new System.Globalization.IdnMapping();
// Pull out and process domain name
str domainName = idn.GetAscii(domainMatch.Groups.get_Item(2).Value);
_emailAddress = System.Text.RegularExpressions.Regex::Replace(
_emailAddress, domainPattern, domainMatch.Groups.get_Item(1).Value + domainName);
}
// Perform basic validation on email address using regex
isValidEmail = System.Text.RegularExpressions.Regex::IsMatch(
_emailAddress, emailPattern,
System.Text.RegularExpressions.RegexOptions::IgnoreCase, System.TimeSpan::FromMilliseconds(250));
}
catch
{
// Email addresses having invalid domains like test@�.com
isValidEmail = false;
}
}
return isValidEmail;
}
No comments:
Post a Comment
Please do not add any spam link in the comment box.