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?
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.
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.
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 'email@example.com' for attribute 'email_address' in instance 'global[global]'. Reason: Invalid Value.</faultstring>
<typ:message>Invalid value 'firstname.lastname@example.org' 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.
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.
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.