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.

Date Format Validation

Pattu
Pattu Posts: 44

I need to validate this format of the date in a field
Example: 2028-07-18 00:00:00.0

Best Answer

  • benken_parasoft
    benken_parasoft Posts: 1,306 ✭✭✭
    Answer ✓

    When I want to look up a regular expression for date and time I usually copy the one from the XML Schema spec: https://www.w3.org/TR/xmlschema11-2/#nt-dateTimeRep

    It isn't the same as the format you are describing but you can base it on that one. You probably want something like this:

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

Answers

  • Pattu
    Pattu Posts: 44

    In SOA test actually

  • benken_parasoft
    benken_parasoft Posts: 1,306 ✭✭✭

    You could use a regular expression to check if the text matches an expected pattern.

    If you are doing the assertion with a Diff tool in Text mode then you can select "Regular Expression" on the Options tab.

    If you are doing the assertion with an XML/JSON Assertor tool then you can add a "Regular Expression Assertion".

  • Pattu
    Pattu Posts: 44
    edited May 24

    I tried Regular expression but there are no options to validate the time and date format. The options available in drop down of Regular Expression are equal to , not equal to , greater than etc,..

  • benken_parasoft
    benken_parasoft Posts: 1,306 ✭✭✭

    Concerning "the time and date format" there is no single standard date and time format. You need to provide a regular expression any time you want to check if some text matches a particular expected pattern, whether it is some particular date-time pattern or the pattern for something else.

  • Pattu
    Pattu Posts: 44

    oh thank you very much I understood now, it worked