Define regular expressions in XML files

You can define regular expressions for input validation in separate XML files.

Reference to these regular expressions can be used in multiple data types that are defined in the datatypes.xml file. Additionally, the reference to the regular expressions can be used in multiple rules that are defined in the different rules XML files. This approach makes it easier to modify the regular expression in one place and the changes take effect both in the datatypes.xml file and different rules XML files. Each regular expression has a unique id that is associated with it. The regular expression files can be registered with the application by adding a context parameter in the <runtime_sandbox>/repository/eardata/smcfs/extn/web.xml file.

To define regular expression for input validation, create an XML file in the following format.

<RegularExpressions>
     <RegularExpression id="" javaPattern="" jsPattern="" blacklistErrorMsg=""
       whitelistErrorMsg=""/>
     <RegularExpression id="" javaPattern="" jsPattern=""/> 
</RegularExpressions>

The following table describes various elements and attributes of the regular expressions XML file.

Note: Any empty attribute is considered as not provided. For example, an element that is defined as <RegularExpression id="dates" javaPattern="" jsPattern="^[a-zA-Z0-9.,!\-/+=_ :]*$"/> is equivalent to <RegularExpression id="dates" jsPattern="^[a-zA-Z0-9.,!\-/+=_ :]*$"/>.

Element/Attribute

Description

RegularExpressions

Required. The regular expressions XML file must have RegularExpressions as root element.

RegularExpression

Optional. Each regular expression must be defined as one RegularExpression element. It can have zero or more occurrences.

id

Required. Unique identifier for the regular expression. This id can be used as reference for this regular expression in various places.

javaPattern

Optional. Regular Expression pattern for doing server-side validation. If not specified, the input validation happens on the client side that is based on the jsPattern attribute value and the server-side validation is not done.

jsPattern

Optional. Regular Expression pattern for doing client-side validation. If not specified, the input validation happens on the server side that is based on the javaPattern attribute value and the client-side validation is not done.

whitelistErrorMsg

Optional. Bundle key for the error message to be displayed, if the white list patterns of the regular expression fail.

blacklistErrorMsg

Optional. Bundle key for the error message to be shown if the black list patterns of the regular expression fail.


For example, if you define a regular expression with an id date, the regular expressions XML file is as follows:

<RegularExpressions>
    <RegularExpression id="dates" javaPattern="^[a-zA-Z0-9.,!\-/+=_ :]*$"
           jsPattern="^[a-zA-Z0-9.,!\-/+=_:]*$" blacklistErrorMsg=""
           whitelistErrorMsg=""/> 
</RegularExpressions>

You can reference the date regular expression in both Rule XML and data types XML.

Use regular expression reference in rule XML

You can provide a reference of the regular expression id in the RegularExpression element when you are defining a rule in the rule XML. For example,

<ValidationRules> 
    <Rule id="" ruleType="Regex" inputType="" inputName="" uri="" 
      maxLength="" minLength="" allowNull="" > 
     <Whitelist> 
        <RegularExpression ref="dates"/> 
     </Rule> 
</ValidationRules>

Use regular expression reference in data types XML

You can provide a reference of the regular expression id in the Regex element when you are defining a regular expression in the datatypes.xml file. For example,

<DataTypes>
    <DataType Name="Date" PpcSize="12" Size="7" Type="DATE">
        <Validation>
             <Regex Ref="dates" />        
        </Validation>
        <UIType Size="8" UITableSize="15"/>
   </DataType> 
</DataTypes>