Home > Enterprise >  Validate the format of timestamp string passed in XML request body
Validate the format of timestamp string passed in XML request body

Time:10-16

I am getting timestamp (2021-10-12T00:00:30.0 05:00) as a field in XML request body, which I need to validate whether it adheres to a specific format (yyyy-MM-ddTHH:mm:ss.fzzz) or not and return error if it does not pass the validation.

I tried using APIM expressions, but it does not allow using DateTime.TryParseExact(), a C# method. If anyone has any pointers, please let me know how can we achieve this?

CodePudding user response:

After further reading the documentation , found out that there is no direct way to check if the timestamp matches the given the format. So went ahead with the regex matching to achieve it.

I used the below mentioned regex

^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d )(([ -]\d\d:\d\d)|Z)$
  • Related