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

J

johkar

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>
 
P

Peter Flynn

johkar said:
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>

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
 
M

Mayeul

johkar said:
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>

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top