Restrict strings in schemas to be upper case or iso format

Hi,

we have a schema with a country field which is a string of maxLength 2 we want those strings to be uppercase always. Is there a way to restrict that in a schema.

It would be even nicer to restrict it to certain ISO codes only.
Similar to the uuid forma. e.g. “format”: “uuid”,

   "market": {
            "type": ["string","null"],
            "description": "Market the user signed up in as ISO 3166-1 alpha-2 country code, e.g. DE, ES, etc.",
            "maxLength" : 2
        },

It would save us a lot converting (e.g. ES, es, Es, eS) further down the pipeline. :wink:

Cheers,

Matthias

Hi Matthias,

you can use a RegEx with the pattern keyword e.g.

"market": {
            "type": ["string","null"],
            "description": "Market the user signed up in as ISO 3166-1 alpha-2 country code, e.g. DE, ES, etc.",
            "maxLength" : 2,
            "pattern": "[A-Z]$"
        },

Best,
David

4 Likes

Nice thanks a lot.