6 Replies Latest reply on Oct 17, 2012 2:11 PM by Ian Clough-Oracle

    Validating e-mail addresses

      Hello, I've been asked to establish methods of validating an e-mail address in OPA. I know that regular expressions can be used on attributes to throw errors at runtime, but we have a need to validate the e-mail string as part of a rule

      i.e. the person's email is valid if........the data given complies with the follow reg exp

      We're just using the determinations engine rather than any input screens hence the need for a rule.

      If there a way of writing this into a word rule? Would the string functions match against regular expressions?

      Thanks for any assistance,
        • 1. Re: Validating e-mail addresses
          Ian Clough-Oracle
          The regular expressions are against the attribute rather than the field on the screen and so are evaluated whenever a value is input for that attribute so you should be able to use this mechanism with the determinations server.
          • 2. Re: Validating e-mail addresses
            Paul Fowler
            Are you sure about the regex?

            If the regex works with determinations, the great. Otherwise, you might also use the following example code for a custom regex function...

            using System;
            using System.Collections.Generic;
            using System.Text;
            using Oracle.Determinations.Engine;
            using Oracle.Determinations.Masquerade;
            using System.Text.RegularExpressions;

            namespace OPAText
            public class TestRegEx : CustomFunction
            public override Object Evaluate(EntityInstance entityInstance, object[] objects)
            Regex regex = new Regex((String)objects[1]);
            return Oracle.Determinations.Masquerade.Lang.Boolean.ValueOf(regex.IsMatch((String)objects[0]));

            package OPAText;

            import com.oracle.determinations.engine.CustomFunction;
            import com.oracle.determinations.engine.EntityInstance;

            public class TestRegEx extends CustomFunction{

                 public Object evaluate(EntityInstance entityInstance, Object[] objects) {
                      return ((String)objects[0]).matches((String)objects[1]);
            • 3. Re: Validating e-mail addresses
              This is great for using real-time input (e.g. via screens in web determinations) where a user has an opportunity to go back and correct an input value before OPA will allow them to proceed, but our determinations server is to be configured like a black box feeding on XML.

              Ideally we'd want to know that an e-mail is valid before it got to us but the controls on that data feed are out of our hands, hence this layer of validation to include in the report.
              • 4. Re: Validating e-mail addresses
                Ian Clough-Oracle
                This is an example response from determination server when an invalid email address is sent.

                <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:i18n="http://www.w3.org/2005/09/ws-i18n"
                <faultstring>Invalid value 'fred.blogs@amco.com' for attribute 'email_address' in instance 'global[global]'. Reason: Invalid Value.</faultstring>
                <typ:message>Invalid value 'fred.blogs@amco.com' for attribute 'email_address' in instance 'global[global]'. Reason: Invalid Value.</typ:message>

                I assume you are using ODS via the SOAP web service APIs. If you are using the engine Java API's directly then you may need to add an event listener to detect these error events but that is failry simple. It's far more convenient to use the standard reg-ex validation and the same logic applies if you have error rules that also do additional checking.
                • 5. Re: Validating e-mail addresses
                  Thanks for responses so far. There's still a desire to prove wether an e-mail is valid through the rules so now I'm thinking along the lines of (and these are intermediate attributes and a little psuedo code here) :

                  the e-mail address is valid if
                  the e-mail address contains an ampersand and
                  the ampersand is not at the start and
                  the ampersand is not at the end and
                  the e-mail address does not contain <write rule for each character that is excluded from use in emails>

                  Obviously this approach is fairly labour intensive to begin with and I don't think the string manipluations are robust enough to give us a 100% solution.

                  • 6. Re: Validating e-mail addresses
                    Ian Clough-Oracle
                    Ok, so assuming you want to influence a determination depending on whether the email address is valid or not rather than simply rejecting invalid ones then I would follow Paul Fowlers advice and write a custom function. Custom functions appear in the rules just like regular functions so you could write something like:
                    the email address is valid if
                    matchRegEx(email address, "some reg ex expression")
                    where matchRegEx is the name of your custom function.