Search code examples
xmlxsdpattern-matchingxsd-validationxml-validation

XSD String pattern which inlcude email with Latin characters


<xsd:element name="MigrCustContactEmail" type="StringX50Email" minOccurs="0" maxOccurs="1"/>


<xsd:simpleType name="StringX50Email">
        <xsd:restriction base="xsd:string">
            <xsd:minLength value="1"/>
            <xsd:maxLength value="50"/>
            <xsd:pattern value="[A-Za-z0-9!#$%&amp;'*+/=?^_`{|}~.\-]+[@][A-Za-z0-9.\-]+"/>
        </xsd:restriction>
    </xsd:simpleType>

It is working fine for normal email but when it comes string like this in XML "groupesÖtoureiffel.paris@maill.com"

It give error : cvc-pattern-valid: Value 'groupes╓toureiffel.paris@mail.com' is not facet-valid with respect to pattern '[A-Za-z0-9!#$%&'*+/=?^_{|}~.-]+[@][A-Za-z0-9.-]+' for type 'StringX50Email'`

Can anyone help me with what to change in the pattern?


Solution

  • You can use

    <xsd:pattern value="[\p{L}0-9!#$%&amp;'*+/=?^_`{|}~.-]+@[\p{L}0-9.-]+"/>
    

    The \p{L} construct matches any Unicode letters.

    Details:

    • [\p{L}0-9!#$%&amp;'*+/=?^_`{|}~.-]+ - one or more Unicode letters, ASCII digits, !, #, $, %, &, ', *, +, /, =, ?, ^, _, `, {, |, }, ~, . or -
    • @ - a @ char
    • [\p{L}0-9.-]+ - one or more Unicode letters, ASCII digits, . or -.