Best Practices while working with Schemas Pattern restrictions

Posted: February 22, 2022  |  Categories: BizTalk Schemas

Yesterday I spoke about how you can apply custom pattern restrictions to properly validate DateTime, Date, and Time formats inside elements or attributes. You can see more about it here:

And I mention that these Regular Expressions can be simple and relatively easier to read if you have some basic knowledge like this one below:

  • \d{4}\d{2}\d{2} – that is a simple format that expects 4 digits followed by 2 additional digits and another 2 digits that is the date in the YYYYMMDD format without validating the accuracy of months or days and where:
    • YYYY is the for digits year, like 2022.
    • MM is the 2 digits month, like 01.
    • DD is the 2 digits day, like 21.

But it can get highly complex that even people with good knowledge have difficulty translating the expression to the expected pattern, like the one below:

  • ^(?:(?:31(\/|-|.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$

It is not simple to look to this RegEx and say: “yep, we are expecting this Date format: MM/DD/YYYY like 12/11/1999, and by the way, it validates the Leap Year!”

Imagine users that don’t have strong know-how about RegEx!

So, what can we do to improve this experience? What are the best practices in these cases?

Best practices

A good best practice to improve readability while documenting your schemas is to add notes to these elements or attributes.

We can and should use the Notes property to enter notes, such as comments related to the business process, that you would like to make about the selected RecordField Element, or Field Attribute node. In these DateTime, Date, and Time cases, we can simply add the expected format in the Notes property, like:

  • Format: YYYY-MM-DD
  • Format: HH:mm:ss
  • Format: YYYYMMDD
  • Format: HHmm
  • Format: YYYY-MM-DD – It validates Leap Year

To accomplish this, we need to

  • Right-click on the Element or Attribute fields in the schema tree view and select the Properties option.
  • On the Properties window, click on the … (three dots) on the Notes property. This action will open a Notes window where you can add all your relevant notes.

Do that to all your elements and fields that are using pattern restrictions.

Even non-technical guys can understand the Schema specification you provide or are consuming. This best practice implementation will also help you improve productivity since you will not spend too much time decompiling Regular Expressions.



You can download the POC: BizTalk Schemas Handle Restrictions on Date from GitHub here:

Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to Top