Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XSD to allow A-Z 0-9 and spaces, but not leading/trailing spaces

5 views
Skip to first unread message

johkar

unread,
Dec 9, 2009, 5:03:07 PM12/9/09
to
I need an XSD restriction for an attribute that will catch this:
name=" AD 01 24"

I need to enforce all caps or numbers or spaces but disallow leading
or trailing spaces. If I could dissallow double spaces that would be
a bonus. This is what I have so far:

<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="collapse"/>
<xs:pattern value="([A-Z0-9 -])*"/>
</xs:restriction>
</xs:simpleType>

Peter Flynn

unread,
Dec 9, 2009, 6:42:19 PM12/9/09
to

You need to prohibit the leading and trailing spaces separately by
specifying that the first character must be a letter or digit; followed
by any mix of letters, digits, spaces, or hyphens; followed by a letter
or digit. The ^ binds to the start of the expression and the $ binds to
the end of the expression:

"^[A-Z0-9][A-Z0-9\ \-]*[A-Z0-9]$"

That's normal RE syntax. I don't know if that is acceptable within the
XSD, and I'm uncertain about how to prohibit a double-space.

///Peter
--
XML FAQ: http://xml.silmaril.ie/

Mayeul

unread,
Dec 10, 2009, 4:24:29 AM12/10/09
to

Actually <xs:whiteSpace value="collapse"/> should eliminate any leading,
trailing and multiple spaces before checking the pattern. That would
prevent invalidation of these spaces.

--
Mayeul

0 new messages