How to filter values using Regular Expressions (RegEx) in Connector Express (CXP).

Document ID : KB000021105
Last Modified Date : 14/02/2018
Show Technical Document Details

Description:

At times, there may be a need to filter out unwanted characters or substrings from entered data or validate that data for formatting (e.g. phone number, SSN, etc.) before storing it. The Regular Expression processing has not yet been fully implemented in Connector Express.

Here is a workaround to implement regular expressions using the JCS override.

Solution:

Use case:

You are creating a custom LDAP/JNDI endpoint and would like to filter-out any non-numeric characters from the telephone number entered by the user.

This will allow different clients connecting to that LDAP to format the data as per their needs without having to account for arbitrary formatting characters [e.g.: ( , - , + , etc.]

Description:

Support for RegEx conversion via connector metadata has not been fully implemented. Instead we recommended that you create a new flexi string type for any attributes that you want to convert and add the regex conversion via the connector type's override connector XML file..

First, define a new custom string type. For this use case, we create a "NumbersOnly" type.

Figure 1

Edit the JCS_HOME\conf\override\jndi\connector.xml to add regex conversion for that string type.

A sample.connector.xml is provided for your convenience; you will need to copy it to a new file named connector.xml.

There is also a JDBC override folder if your use case is for JDBC. See the attached example for JDBC.

** Note that is appears that in 12.6 the sample.connector.xml file for JDBC is not being created. You will need to manually create a 'jdbc' subdirectory under JCS_HOME\conf\override and use the attached connector.xml as a starting point.

The new regex conversion section looks like this:

<!-- remove non digit characters from the string, e.g. formatting characters in phone numbers -->
<entry key="FLEXI_STR:numbersonly">
<bean class="com.ca.jcs.converter.attr.RegexAttributeConverter">
<!-- style -->
<constructor-arg>
<value>perl5</value>
</constructor-arg>
<!-- regex -->
<constructor-arg>
<value>s/\D//g</value>
</constructor-arg>
</bean>
</entry> 

Restart the Java Connector Server for the changes to take effect.

In your connector, you will now define the relevant attribute (TelephoneNumber, in this case) as type "flexi - numbersonly".

Figure 2

Save and deploy your connector as usual.

File Attachments:
TEC584446.zip