XMLspy - dd/mm/yy Pattern problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robtyketto
    New Member
    • Nov 2006
    • 108

    XMLspy - dd/mm/yy Pattern problem

    Greetings,

    I was looking for a regular expression to validate dates in the format dd/mm/yy including leap year validation.

    I found a regular expression from http://regexlib.com (see below)

    Code:
    ^(((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))))$
    Which I then formatted taking off the start and end tags and also changing \/ which i believe represents a forward slash to / as its not support by xmlspy.

    This leaves me with the following :-

    Code:
    (((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))))
    However when entering my dd/mm/yy xmlspy points to the / not being valid in my date 01/07/07

    Can anyone help me to resolve this?

    Thanks
    Rob
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Your pattern looks right.
    It could even be shortened to:
    [code=txt]((31/(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[048]|[2468][048]|[13579][26]))))[/code]

    Comment

    • robtyketto
      New Member
      • Nov 2006
      • 108

      #3
      Thanks for the reply I replaced my pattern with the one you posted and all works !!

      Very happy : - )

      Thanks again
      Rob

      Comment

      • robtyketto
        New Member
        • Nov 2006
        • 108

        #4
        Ok so now I decided to have the date field as dd/mm/yy hh:mm

        and found the regular expression list below on the web (does dd/mm/yy or dd/mm/yy hh:mm:ss, modifying \/ to / so xmlspy can process the forward slash.

        Code:
        <xs:pattern value="((((([0-1]?\d)|(2[0-8]))/((0?\d)|(1[0-2])))|(29/((0?[1,3-9])|(1[0-2])))|(30/((0?[1,3-9])|(1[0-2])))|(31/((0?[13578])|(1[0-2]))))/((19\d{2})|([2-9]\d{3}))|(29/0?2/(((([2468][048])|([3579][26]))00)|(((19)|([2-9]\d))(([2468]0)|([02468][48])|([13579][26]))))))\s(([01]?\d)|(2[0-3]))(:[0-5]?\d){2}"/>
        Again when creating an xml file from the schema it complains at the forward slash. Im left confused and frustrated, the sheer size of his makes it difficult to read.

        If anyone has a regular expression for dd/mm/yy hh:mm (no seconds!) I would be very grateful

        Thanks
        Rob

        Comment

        • jkmyoung
          Recognized Expert Top Contributor
          • Mar 2006
          • 2057

          #5
          You should just be able to delete the {2} at the end, since that is for both minutes and seconds.
          Assuming you always have 2 digits hours and minutes,

          ((31/(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[048]|[2468][048]|[13579][26]))))(([01]\d)|(2[0-3])):[0-5]\d

          Comment

          • robtyketto
            New Member
            • Nov 2006
            • 108

            #6
            Thanks again, I realised it was the same issue as before I had the element type as xs:datetime and not xs:string.

            xs:datetime I suppose does not expect a forward slash /

            Cheers
            Rob

            Comment

            Working...