Date Format Validation
Best 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+)?))
1
Answers
-
In SOA test actually
0 -
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".
0 -
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,..
0 -
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.
0 -
oh thank you very much I understood now, it worked
1 -
hi @benken_parasoft
in my test , there is a value in XML like below and we need to validate the characters should not exceed 11 characters in total including decimals. Now the REG exg assertion should match "^-?\d{1,11}(.\d{1,2})?$|^-?\d{1,11}$" failed with error : Error Message:
Regular Expression Assertion: Actual value, 0.0591, must match the provided regular expression:
^-?\d{1,11}(.\d{1,2})?$|^-?\d{1,11}$ with case sensitivity enforcedAdditional Details:
Actual value, 0.0591, must match the provided regular expression:
^-?\d{1,11}(.\d{1,2})?$|^-?\d{1,11}$ with case sensitivity enforcedThe actual xpah i need to validate is from an XML
0.05910 -
we need to validate the characters should not exceed 11 characters in total
You can do this at least a couple different ways using the XML Assertor tool. You could create a Regular Expression Assertion with regex like ".{0,11}". You could also create a Value Assertion with XPath like "string-length(/path/to/element/string()) <= 11" with expected value of "true".
0