Validation of email is one of the feature that has been most commonly used in Dynamics AX. We being a developer many times came across with the requirements that needs email validation so i have written a function that uses regex regular expression to validate emails.
Retirements:
1)We need to declare a const str in the class that will contain all characters,
public const Str MatchEmailPattern =
@"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
+ @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
+ @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
+ @"([\w-]+\.)+[a-zA-Z]{2,4})$";
2) The above, MatchEmailPattern will be called within the function "validateEmail" that will return boolean
//function "validateEmail"
private boolean validateEmail(Email _email)
{
boolean ret = true;
Boolean VerifEmails;
System.Text.RegularExpressions.Match emailMatch;
if(_email != '')
{
new InteropPermission(InteropKind::ClrInterop).assert();
emailMatch = System.Text.RegularExpressions.Regex::Match(_email,MatchEmailPattern);
VerifEmails = emailMatch.get_Success();
ret = VerifEmails;
CodeAccessPermission::revertAssert();
}
return ret;
}
Retirements:
1)We need to declare a const str in the class that will contain all characters,
public const Str MatchEmailPattern =
@"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
+ @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
+ @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
+ @"([\w-]+\.)+[a-zA-Z]{2,4})$";
2) The above, MatchEmailPattern will be called within the function "validateEmail" that will return boolean
//function "validateEmail"
private boolean validateEmail(Email _email)
{
boolean ret = true;
Boolean VerifEmails;
System.Text.RegularExpressions.Match emailMatch;
if(_email != '')
{
new InteropPermission(InteropKind::ClrInterop).assert();
emailMatch = System.Text.RegularExpressions.Regex::Match(_email,MatchEmailPattern);
VerifEmails = emailMatch.get_Success();
ret = VerifEmails;
CodeAccessPermission::revertAssert();
}
return ret;
}
Comments
Post a Comment