Validate Email Address with non-English characters
The following code snippet is a REGEX that validates characters that are not in English, as well as English characters. The class method "test" takes an email address and validates it based on this additional criteria:
Class brianpalmund.validateSpecial Extends %RegisteredObject
{
// I had an issue validating email addresses, and it seems that doing a 100% safe validation is near impossible.
// I found a RegEx validation rule that seemed to do the job with the only problem being on handling special international characters.
//
//This method matches almost all of our 1.8 mil. email addresses correct and catches almost all invalid ones:
//
ClassMethod test(email As %String) As %Boolean
{
set specialCharacters = "wáàãââæåçéèêëìíîïñòóôõöøùúûüýÿ"
quit $MATCH(email, "^[a-zA-Z0-9"_specialCharacters_".!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9"_specialCharacters_"](?:[a-zA-Z0-9-"_specialCharacters_"]{0,61}[a-zA-Z0-9"_specialCharacters_"])?(?:\.[a-zA-Z0-9"_specialCharacters_"](?:[a-zA-Z0-9-"_specialCharacters_"]{0,61}[a-zA-Z0-9"_specialCharacters_"])?)*$")
}
}
Here's a link to the code on GitHub: https://github.com/intersystems-community/code-snippets/blob/master/src/cls/brianpalmund/validateSpecial.cls
Discussion (0)0