[facet 'pattern'] The value is not accepted by the pattern

A value that does not match the regular expression the schema requires.

The message, as the validator reports it
Element 'code': [facet 'pattern'] The value 'ab-12' is not accepted by the pattern '[A-Z]{3}-[0-9]{4}'.

Why it happens

  • Wrong case, length or separators: identifiers, postal codes, IBANs, phone numbers.
  • Leading or trailing spaces. XSD patterns match the whole value, as if wrapped in ^…$.

How to fix it

The message shows the pattern. Format the value to match all of it; for long patterns, test the value against it in a regular-expression tool, keeping in mind that XSD has no ^, $ or lazy quantifiers.

Example

Validated against order.xsd, below.

Reports the error
<order currency="EUR">
  <id>A-1</id>
  <qty>1</qty>
  <code>ab-12</code>
</order>
Fixed
<order currency="EUR">
  <id>A-1</id>
  <qty>1</qty>
  <code>ABC-0012</code>
</order>
order.xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="order">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="id" type="xs:string"/>
        <xs:element name="qty" type="xs:int"/>
        <xs:element name="status" type="Status" minOccurs="0"/>
        <xs:element name="code" type="Code" minOccurs="0"/>
        <xs:element name="note" type="Short" minOccurs="0"/>
      </xs:sequence>
      <xs:attribute name="currency" type="xs:string" use="required"/>
    </xs:complexType>
  </xs:element>
  <xs:simpleType name="Status">
    <xs:restriction base="xs:string">
      <xs:enumeration value="open"/>
      <xs:enumeration value="paid"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="Code">
    <xs:restriction base="xs:string">
      <xs:pattern value="[A-Z]{3}-[0-9]{4}"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="Short">
    <xs:restriction base="xs:string">
      <xs:maxLength value="10"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>