0

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

declare namespace 
ns123='urn:lt:sb:xmlns:services:customers:customerinformationfile:GetCustByGlobalId:1.2';
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).

1 Answer 1

1

Try

^[0-9-]{10}$

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.

2
  • 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
    Commented May 10, 2018 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.
    Commented May 10, 2018 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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