If you have a comment on this topic, contact Aptify Documentation. If you want to return to the Aptify Community Site, please click here.

About the Associates Entity Email Field Validation Script

This field includes a validation script that compares the value provided by a user against a regular expression to determine if the email address is in an acceptable format. Within the context of the sample application, this requirement is defined in BPR4: Enforce Email Address Format and the implementation is described in About the Data Quality Design for the Sample Application.

It follows this process:

  • Uses a geRecord.GetValue("Email").ToString <> " " statement to retrieve the value of the Email field from the current record's GE and determine if the Email field is blank. If blank, no further validation is applied.
  • If the Email value is not blank, the script defines a regular expression for an e-mail address format and matches the Email value from the record against the regular expression.
  • If the Email value matches the regular expression, the value passes the validation test and the script calls oResult.Success = True.
  • If the Email value does not match the regular expression, the value fails the validation test. The script calls oResult.Success = False and oResult.Message to display an error message to the user that the value entered is not a valid Email address.
  • Note that the sample script also includes code to handle situations where the script fails for unexpected reasons.

The full text of the script appears below:

 ' DEMO VALIDATION SCRIPT FOR MOTOR LOANER VEHICLE TRACKING SYSTEM '
----------------------------------------------------------------------------------------------------------------------

' This script enforces the business rule that only allows for 
' valid email addresses to be entered for Associates.
'
'Field Validation Scripts can access this record's properties via geRecord.
'The Results of a script are returned via oResult.Success = [True|False]
'
'This sample script uses .Net's RegularExpression class to compare
'the entered email address against a regular expression.

Try
     'Only validate the Email field if it is not blank since the Email field is not required
      If geRecord.GetValue("Email").ToString <> "" Then
                  Dim emailRegEx As System.String = "^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$"
                  Dim myRegEx As New System.Text.RegularExpressions.Regex(emailRegEx)
                  Dim myMatch As System.Text.RegularExpressions.Match
                  myMatch = myRegEx.Match(geRecord.GetValue("Email").ToString)
                  If myMatch.Success Then
                          oResult.Success = True
                  Else
                         'email did not pass regular expression test
                         oResult.Success = False
                         oResult.Message = geRecord.GetValue("Email").ToString & _                                                                                                       "
                                 is not a valid email address. Please reenter the Associate's email."
                  End If
      Else
                  'nothing to validate, return true         
                  oResult.Success = True
      End If
Catch
      'Validation Script Failed
      oResult.Success = False
      oResult.Message = "The Email Field Validation script failed unexpectedly. " & _
                                 "Check the script for logical errors."
End Try

The Sample Application also contains a validation script that performs the same function for the Email field in the Customers entity.

Copyright © 2014-2019 Aptify - Confidential and Proprietary