1

I was trying to validate a particular field in an JSON request file.

the field should be between 1-160 characters in length and should NOT allow any special characters .

I tried the below . But it does not work . Any inputs will be deeply appreciated.

"SMSContent": {
              "id": "http://jsonschema.net/Request/Data/SMSContent",
              "type": "string",
               "pattern": "[a-zA-Z]{1,160}"
              }
unor
  • 92,415
  • 26
  • 211
  • 360
user1117723
  • 153
  • 2
  • 10
  • I also tried the below . does not work :( "SMSContent": { "id": "http://jsonschema.net/Request/Data/SMSContent", "type": "string", "minLength": 1, "maxLength": 160, "pattern": "[0-9A-Za-z]{1,160}" } – user1117723 May 05 '16 at 21:01
  • Have you tried without `{1,160}` since you are using `minLength` and `maxLength`? Not all regex implementation support the {n,m} notation. That could be the problem you are running into. – Jason Desrosiers May 05 '16 at 21:59
  • 1
    Possible duplicate of [Using RegEx in JSON Schema](http://stackoverflow.com/questions/16491973/using-regex-in-json-schema) – Paul Sweatte Sep 11 '16 at 09:34
  • You need to add a $ to indicate the end of the string like this: "pattern": "[a-zA-Z]{1,160}$" – damorin Sep 27 '16 at 11:52

0 Answers0