W3C home > Mailing lists > Public > xmlschema-dev@w3.org > December 2001

Re: pattern question

From: Jeni Tennison <jeni@jenitennison.com>
Date: Wed, 19 Dec 2001 19:23:30 +0000
Message-ID: <14428490607.20011219192330@jenitennison.com>
To: "Arigapudi, Shyam" <Shyam.Arigapudi@ugs.com>
CC: "'xmlschema-dev@w3.org'" <xmlschema-dev@w3.org>
Hi Shyam,

> I would like to restrict a string based on a pattern:
>                (The string cannot have the set:    ?:,'<>/*\|= and " )
> <xsd:element name="LayerName">
>                         <xsd:simpleType>
>                                 <xsd:restriction base="xsd:string">
>                                         <xsd:minLength value="1"/>
>                                         <xsd:maxLength value="255"/>
>                                         <xsd:pattern
> value="[^?:,'/\\\*&quot;&gt;&lt;|=]"/>  <!--Need suggestion here -->
>                                 </xsd:restriction>
>                         </xsd:simpleType>
> </xsd:element>

That looks fine (though I think the * has no meaning in a character
group, so you don't have to escape it) - the only thing you're missing
is a + or * or something after the character range to enable the
pattern to match strings with more than one character in them:

  <xs:pattern value="[^?:,'/\\*&quot;>&lt;|=]+" />

Or if you want, you could specify the number of allowable characters
in the pattern as well as through the minLength/maxLength facets:

  <xs:pattern value="[^?:,'/\\*&quot;>&lt;|=]{1,255}" />

(BTW, I wouldn't get rid of the minLength/maxLength facets even if you
did that - they would enable some level of validation even from schema
processors that don't understand regular expressions.)

If you want to ban all punctuation, you could more simply use:

  <xs:pattern value="\P{P}{1,255}" />



Jeni Tennison
Received on Wednesday, 19 December 2001 14:23:32 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:14:56 UTC