Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

How to validate date format in request attribute

ashwini
ashwini Posts: 11

I have to validate that a field in request of a Rest API is having YYYY-MM-DDThh:mm:ss.sssZ format. Any help is most welcome.

TIA

Comments

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited April 2020

    I would use a "Regular Expression Assertion" in a JSON/XML Assertor tool.
    The Diff tool's Text mode also has a "Regular Expresion" option.

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited April 2020

    For ISO 8601 or RFC3339 date-time format, I've used a regex like this. I have it split across multiple lines for readability but you would normally put it all on one line:

    -?([1-9][0-9]{3,}|0[0-9]{3})
    -(0[1-9]|1[0-2])
    -(0[1-9]|[12][0-9]|3[01])
    T(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\.[0-9]+)?|(24:00:00(\.0+)?))
    (Z|(\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?