I need to match, exact length of a string and I'm using below code for that :

declare namespace 
matches(//ns123:legalCode, "[0-9-]{10}")

Problem is that it works only for greater length (for example, if field content is 11, it fails, but it doesn't, if the content is 9).




instead of your [0-9-]{10}

Your expression just checks that there is a substring of 10 digits or dashes in your string. Wrap it with ^..$ to specify that it should strictly fall between start and end of your string.

  • Thank you. It works! But for one case it doesn't, why is it so? matches(//ns123:birthDate, "^[T0-9-:]{24}$") Content is: 1938-08-09T00:00:00.000 – Jdreamer May 10 '18 at 12:49
  • Because: 1 - there is a dot in your content, 2 - there are 23 symbols. Your query should be: ^[T0-9-:\.]{23}$ – Alexey R. May 10 '18 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.