How to validate date format in request attribute

ashwiniashwini 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_parasoftbenken_parasoft Posts: 908 ✭✭✭
    edited April 28

    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_parasoftbenken_parasoft Posts: 908 ✭✭✭
    edited April 28

    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))?
    
Sign In or Register to comment.