# cvc-pattern-valid: the value does not match the XSD pattern

The element’s value fails a pattern restriction on its simple type. XML Schema regular expressions describe an accepted lexical shape; they are not a general-purpose JavaScript or Java regex configuration. Inspect the actual xs:pattern before changing application regex code.

## Literal meaning

The SKU type in this example requires two uppercase letters, a hyphen and three digits. ab204 lacks both the required letter case and separator. BK-204 satisfies the declared pattern, so the corrected XML passes with the same XSD. Xerces also emits the broader cvc-type.3.1.3 message for the enclosing value.

## Three common causes

1. The value has the wrong case, separators or character class. Visually similar Unicode punctuation can differ from the literal characters permitted by the pattern.
2. A regex from another language was copied into the schema. Escapes, character classes and unsupported constructs must follow XSD regex rules rather than a browser regex tester.
3. Whitespace processing changes what reaches the pattern check. A string-derived type and a token-derived type can treat surrounding or repeated whitespace differently.

## Repair

Open the type restriction and read the pattern together with its base type and any inherited restrictions. Compare a known passing value with the failing text character by character. Reproduce the check in an XSD validator, then make the smallest contract-preserving correction. Test nearby values such as lowercase letters or a missing digit so the producer’s normalization does not accept an unintended SKU shape.

## Namespace checks

A pattern failure normally means a declaration was found and its value restriction ran. A namespace mistake becomes relevant if the wrong element or xsi:type caused an unexpected restriction to be selected. First confirm which simple type supplied the reported pattern; changing xmlns will not uppercase letters or insert a hyphen.

Do not “fix” this by deleting xs:pattern or replacing it with a catch-all expression. The pattern may encode a receiver’s identifier format. If the receiver’s documented SKU format has changed, update the contract through its normal version process and test both old and new producers against that version.

## Pattern facet / cvc-pattern-valid — Broken

```xml
<sku>ab204</sku>
```

```xml
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="sku">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:pattern value="[A-Z]{2}-[0-9]{3}"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
</xs:schema>
```

[Open broken pair](https://xsdhub.com/?example=parser-pattern&variant=bad#workbench)

## Pattern facet / cvc-pattern-valid — Corrected

```xml
<sku>BK-204</sku>
```

```xml
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="sku">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:pattern value="[A-Z]{2}-[0-9]{3}"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
</xs:schema>
```

[Open corrected pair](https://xsdhub.com/?example=parser-pattern&variant=good#workbench)

### Apache Xerces-J 2.12.2

```text
cvc-pattern-valid: Value 'ab204' is not facet-valid with respect to pattern '[A-Z]{2}-[0-9]{3}' for type '#AnonType_sku'.
cvc-type.3.1.3: The value 'ab204' of element 'sku' is not valid.
```

Corrected: PASS.

### .NET 8.0.33 · System.Xml.Schema

```text
The 'sku' element is invalid - The value 'ab204' is invalid according to its datatype 'String' - The Pattern constraint failed.
```

Corrected: PASS.

### XSDHub libxml2/WASM 0.7.2

```text
Element 'sku': [facet 'pattern'] The value 'ab204' is not accepted by the pattern '[A-Z]{2}-[0-9]{3}'.
```

Corrected: PASS.

### XSDHub xmlschema 4.3.1 · XSD 1.0

```text
value doesn't match any pattern of ['[A-Z]{2}-[0-9]{3}']
```

Corrected: PASS.

Saxon EE was not available; no measured Saxon wording is claimed.

[All parser codes](https://xsdhub.com/learn#parser-error-codes)
[Download engine evidence](https://xsdhub.com/parser-error-examples/engine-evidence.json)
