This discussion is archived
6 Replies Latest reply: Oct 17, 2012 7:11 AM by Ian Clough RSS

Validating e-mail addresses

865068 Newbie
Currently Being Moderated
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,
Mark.
  • 1. Re: Validating e-mail addresses
    Ian Clough Explorer
    Currently Being Moderated
    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 Explorer
    Currently Being Moderated
    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...

    *.Net:*
    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]));
    }
    }
    }

    Java:
    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
    865068 Newbie
    Currently Being Moderated
    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 Explorer
    Currently Being Moderated
    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"
    xmlns:typ="http://oracle.com/determinations/server/10.4/DeterminationsServerErrorTest/assess/types">
    <SOAP-ENV:Header>
    <i18n:international>
    <i18n:locale>en_US</i18n:locale>
    <i18n:tz>GMT+0100</i18n:tz>
    </i18n:international>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
    <SOAP-ENV:Fault>
    <faultcode>SOAP-ENV:Client</faultcode>
    <faultstring>Invalid value 'fred.blogs@amco.com' for attribute 'email_address' in instance 'global[global]'. Reason: Invalid Value.</faultstring>
    <detail>
    <typ:error-response>
    <typ:code>com.oracle.determinations.server.exceptions.AttributeValueException</typ:code>
    <typ:message>Invalid value 'fred.blogs@amco.com' for attribute 'email_address' in instance 'global[global]'. Reason: Invalid Value.</typ:message>
    </typ:error-response>
    </detail>
    </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

    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
    865068 Newbie
    Currently Being Moderated
    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.

    Thanks,
    Mark.
  • 6. Re: Validating e-mail addresses
    Ian Clough Explorer
    Currently Being Moderated
    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.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points