Laxmikanth Samudrala
Laxmikanth Samudrala

Reputation: 2243

can we validate date from XSD in MM-DD-YYYY format?

can we specify MM-DD-YYYY format date restriction in XSD on element which we want to restrict ?

Upvotes: 3

Views: 9245

Answers (2)

Jon Hanna
Jon Hanna

Reputation: 113222

Yes, with a pattern restriction on a string.

On a machine-readable format I'd advise using the International standard (which is also your national standard ANSI X3.30) as it is expected, widely supported and well known.

If it's intended to be displayed to a human directly rather than processed by the consuming machine, the a local convetion is fine, though it's important to be clear that it's being used.

Upvotes: 1

schoetbi
schoetbi

Reputation: 12846

Yes it is possible with an regex

<xsd:simpleType name="Date">
   <xsd:restriction base="xsd:string">
     <xsd:pattern value="\d{2}-\d{2}-\d{4}"/>
   </xsd:restriction>
</xsd:simpleType>

Left is of course that the range should be checked also. Maybe you can extend the regex to only accept certain numbers.

Upvotes: 3

Related Questions