Validate Metadata Field with multiple values

I’m using a regex to validate a Metadata Field. It works perfectly when there is only one value, but fails when there are multiple values. For example…

1234 3456 5678

Should I be modifying the Regex to accommodate multiple values or do I use template language to do so?

Thanks

What is your validation goal for this metadata field? For example:

  • Force just one number. Raise a validation error if the user enters two or more.
  • Force at least two numbers. Raise a validation error if the user enters just one.
  • Validate all numbers equally regardless of quantity. Raise a validation error if one of the numbers don’t match the rule.

My guess is that you want to allow only numbers of 4 digits separated by spaces. There can be either 1 or more numbers in the metadata. If that is the case then this pattern will do so:

(\d{4}\s*)+

This means:

  • ()+ at least one group (more allowed but optional) of
  • \d{4}\s* required four digits and any number of optional spaces between the groups

Enter is as such:

{'pattern':'(\d{4}\s*)+'}

image

Cases:

1 Like

Selecting unlimited spaces part of the Regex was the key to solving it for me.

\s*

Thank you for digging into this and getting an answer so quickly!

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.