Regular expression does not work in pattern facet?

J

Johann Sijpkes

Hi,
Just before going mad I thought asking this newsgroup would be a good idea.
I want to validate dates using a schema but somehow the regexp is not
performed by the validator?
(at w3c..).
I have a small regular expression which works fine, but the long beast just
validates. Also on invalid dates like 35/07/04 (dd/mm/yy). Anyway, in the
online regexp tester it works fine ?
I have no idea why this is..
Is the expression too long? If so, is there a workaround?

Thanks,
Johann

This is the code:

<xsd:simpleType name="date_type" >
<xsd:restriction base="xsd:string">
<xsd:minLength value="8" />
<xsd:maxLength value="8" />
<xsd:pattern value="^\d{2,2}/\d{2,2}/\d{2,2}$" /> <!-- This regexp
works, the next does not -->

<xsd:pattern value=
"^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/(\d{2}))|((0[1-9]|[12]\d|30)\/(
0[13456789]|1[012])\/(\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/(\d{2}))|(29\/02\/((
0[48]|[2468][048]|[13579][26])|(00))))$" />
</xsd:restriction>
</xsd:simpleType>

<!-- Credits for the regular expression go to Dany Lauener who posted this
on the regexp library
http://www.regexlib.com/REDetails.aspx?regexp_id=488

Regular expressions can be tested at :
http://www.regexlib.com/RETester.aspx
 
H

Henry S. Thompson

Johann Sijpkes said:
I have a small regular expression which works fine, but the long beast just
validates. Also on invalid dates like 35/07/04 (dd/mm/yy).

This is the code:

<xsd:simpleType name="date_type" >
<xsd:restriction base="xsd:string">
<xsd:minLength value="8" />
<xsd:maxLength value="8" />
<xsd:pattern value="^\d{2,2}/\d{2,2}/\d{2,2}$" /> <!-- This regexp
works, the next does not -->

<xsd:pattern value=
"^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/(\d{2}))|((0[1-9]|[12]\d|30)\/(
0[13456789]|1[012])\/(\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/(\d{2}))|(29\/02\/((
0[48]|[2468][048]|[13579][26])|(00))))$" />
</xsd:restriction>
</xsd:simpleType>

Apologies for your difficulties -- XSV uses Python's builtin regexp
library, which only supports a subset of full Unicode/XML Schema
regexps. So XSV tries to check before using the pattern that it will
compile OK, and it rejects \ escapes python doesn't support. Which
includes \/. This is my bug, but it won't get fixed for a while . . .

But \/ is not needed for your pattern to work, so just
change all \/ to / in your pattern, and it will be fine.

ht
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: (e-mail address removed)
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
 
J

Johann Sijpkes

Thanks Henry!
The proposed solution indeed resolved the issue!

library, which only supports a subset of full Unicode/XML Schema
regexps. So XSV tries to check before using the pattern that it will
compile OK, and it rejects \ escapes python doesn't support. Which
includes \/. This is my bug, but it won't get fixed for a while . . .

But \/ is not needed for your pattern to work, so just
change all \/ to / in your pattern, and it will be fine.

ht
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: (e-mail address removed)
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged
spam]
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top