Sunday, November 28, 2010

Validating incoming String of Date format using Regular Expression

I was recently trying to restrict the format of the incoming variable so as to adhere it to the date format like 27-Nov-2010 04:17:37 PM. Well, this had to be pretty simple by using the xp20:matches function that can be used to match a string pattern against a regular expression. I used my function as

xp20:matches(bpws:getVariableData('inputVariable','payload','/ns3:PropertyDetails/ns3:PropertyValueToUpdate'), '^(0[1-9]|[12][0-9]|3[01])[- /.](Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[- /.](19|20)\d\d (0[1-9]|1[012])[:](0[1-9]|[12345][0-9])[:](0[1-9]|[12345][0-9]) (AM|PM)$')

Ooops. This was not working and but telling me Internal Xpath Error. Well the reason was that getVariableData() function gets the data from the XML schema element in Object format rather than in String. Finally, all I did was that I used the string() function to convert the object from variable data and it worked without any issue.

xp20:matches(string(bpws:getVariableData('inputVariable','payload','/ns3:PropertyDetails/ns3:PropertyValueToUpdate')), '^(0[1-9]|[12][0-9]|3[01])[- /.](Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[- /.](19|20)\d\d (0[1-9]|1[012])[:](0[1-9]|[12345][0-9])[:](0[1-9]|[12345][0-9]) (AM|PM)$')

Just a small learning…

1 comment:

  1. Do you have any idea on how to validate the date format of CCYYMMDDHHMMSS

    ReplyDelete