Search code examples
jsonvalidationjson-schema-validator

What is the correct pattern to validate such in address field in json schema


How to validate that the "street" should contain only upper case. Though it can contain number and spaces

For example: should accept below

  • 1 ABC ST
  • 1 ABCST
  • ABCST
  • ABCST 1

should not accept below

  • 1 aBC ST
  • 1 ABCSt
  • ABcST
  • abcst 1

Solution

  • You can use a regular expression to constrain a string. In your case it would be something like this.

    {
       "type": "string",
       "pattern": "^[ A-Z0-9]+$"
    }
    

    You can make the regular expression more advanced to not allow leading and trailing space etc.