title: Validate custom date and time in XML with XSD
body: <p>I have to validate dates formatted like this 09.02.2015 (DD.MM.YYYY) and times 14:05 (HH:MM), but can't find a way to do this.</p>
  
  <p>Here's an example:</p>
  
  <p>XML:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;root&gt;
      &lt;testdate&gt;09.02.2015&lt;/testdate&gt;
      &lt;testtime&gt;14:05&lt;/testtime&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>XSD:</p>
  
  <pre><code>&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
             xmlns:sql="urn:schemas-microsoft-com:mapping-schema"&gt;
      &lt;!-- Root element --&gt;
      &lt;xs:element name="root"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element name="testdate" type="zsdate"/&gt;
                  &lt;xs:element name="testtime" type="zstime"/&gt;
              &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
  
      &lt;!-- Date format used to validate dates formatted like 01.01.2015 --&gt;
      &lt;xs:simpleType name="zsdate"&gt;
          &lt;xs:restriction base="xs:date"&gt;
              &lt;xs:pattern value="^(0[1-9]|[12][0-9]|3[01]).(0[1-9]|1[012]).(19|20)\d\d$"/&gt;
          &lt;/xs:restriction&gt;
      &lt;/xs:simpleType&gt;
  
      &lt;!-- Time format used to validate times formatted like 11:55, 23:59 etc. --&gt;
      &lt;xs:simpleType name="zstime"&gt;
          &lt;xs:restriction base="xs:time"&gt;
              &lt;xs:pattern value="^(0[0-9]|[1][0-9]|2[1-3]):([0-5][1-9])$"/&gt;
          &lt;/xs:restriction&gt;
      &lt;/xs:simpleType&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>I've tried to validate the XML with the notepad++ XML plugin and with this <a href="http://www.freeformatter.com/xml-validator-xsd.html" rel="nofollow">XML validator</a>.</p>
  
  <p>Notepad++ output:</p>
  
  <blockquote>
    <p>Validation of current file using XML schema:</p>
    
    <p>ERROR: Element 'testdate': '09.02.2015' is not a valid value of the atomic type 'zsdate'.<br>
    ERROR: Element 'testtime': '14:05' is not a
    valid value of the atomic type 'zstime'.</p>
  </blockquote>
  
  <p>When testing the regular expression with <a href="http://www.regular-expressions.info/javascriptexample.html" rel="nofollow">Regular Expression Tester</a>, it matches correctly.<br>
  I've tried changing the types from <code>xs:date</code> and <code>xs:time</code> to <code>xs:string</code>, but the validation result is the same.</p>
  
  <p>Any idea what I'm doing wrong?</p>