It's easy to validate an email address for a web application in JavaScript with the help of since JavaScript follow the standards. When you need to do the same for a notes application you are either stuck with the -formula or a to be able to use it in lotusscript (with evaluate) or by creating a VBScript RegEx object (I haven't looked into this myself but it seems to be ).
Apart from this the regular expression functionality in lotusscript actually except the which do have some of the basic functionality of regular expressions but not enough for more advanced checks - like email validation.
One way of accomplishing it rather painless is to create a java agent that does the check since also Java support the standards of regular expressions. What you need is basically the .
In my application I have created a Java script library with different methods to use for washing data but I will present only this function here in a simple Java agent to demonstrate. Remember that if you really must use lotusscript to run the code and the check you can call java objects from lotuscript. I haven't tried it myself yet but here is a .
Just paste the following code into a new java-agent, select "None" as runtime-target and run and you'll see the result in the Java Debug Console.
import lotus.domino.*; import java.util.regex.Matcher; import java.util.regex.Pattern;
public class JavaAgent extends AgentBase {
/** * Constant regular expressions. * The separation of the string below is only for the blog entry to display correct. * You will of course not need it when running the code. */ public final static String EMAIL_REGEX = "^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*" + "+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?";
/** * @param Regular expression * @param Pattern to check against the regular expression * @return True if the pattern is valid against the regular expression and else false */ public boolean isValidString(String sRegEx, String sCheckPattern) { Pattern p = Pattern.compile(sRegEx); Matcher m = p.matcher(sCheckPattern); return m.matches(); }
public void NotesMain() {
try { Session session = getSession(); AgentContext agentContext = session.getAgentContext(); if (isValidString(EMAIL_REGEX, "an.address@test")) { System.out.println("Valid email address!"); } else { System.out.println("Invalid email address!"); }
} catch(Exception e) { e.printStackTrace(); } } }
|
This is compared to other solutions a small amount of code and pretty easy to understand and besides this it covers 99,99% of all email addresses in actual use today according to .
The ultimate and fail-proof official standard (RFC 2822) is extremely long and complex.
but you're recommended not to use it.
Read more about this on the provided link above to regular-expressions.info.