Sunday, May 31, 2009

Using Regular Expressions with BPEL

In file based operations we may have requirements to read the content of the file and validate them. By validation, I mean


  • Data type of the fields

  • Date format of the date fields

Validating these becomes simple, when using regular expressions with BPEL.


xp20:matches() is a function which can be used to compare data with regular expressions. This function returns true when the input matches the given expression.


Lets take them case by case



  1. Validation of alpha fields can be done as

xp20:matches(bpws:getVariableData('Variable_firstname'),'^[A-Z]*$')


2. Validation of numeric fields can be done as


xp20:matches(bpws:getVariableData('Variable_streetnumber'),')^[0-9]*$')


3. Validation of date field with format yyyymmdd can be done as


xp20:matches(bpws:getVariableData('Date'),'^(1920)\d\d(0[1-9]1[012])(0[1-9][12][0- 9]3[01])$')

4. Validation of datetime field can be done as

xp20:matches(bpws:getVariableData('Variable_datetime'),'^([1-9][0-9]*)?[0-9]{4}(1[0-2]0[1-9])(3[0-1]0[1-9][1-2][0-9])(2[0-3][0-1][0-9])[0-5][0-9][0-5][0-9]$')


xp20:matches takes string input.So if a variable is not string, please typecast them to string to get the results.


eg : xp20:matches(string(bpws:getVariableData('Variable_firstname')),'^[A-Z]*$')


Format Date in Oracle BPEL

Often I have noticed that our applications vary largely on the formats required for date. But the date conversion in Oracle BPEL does not work when using the format 'mm/dd/yy' or 'mmddyy'.The correct format for converting

current date to date like 12 dec 2009 is

xp20:format-dateTime(xp20:current-dateTime(),'[D]-[[MN,*-3]-[Y]').
current date to date like 091212 is

xp20:format-dateTime(xp20:current-dateTime(),'[Y01][M01][D01]')
current date to date like 12122009 is

xp20:format-dateTime(xp20:current-dateTime(),'[M01][D01][y0001]'