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}"
              }
4
  • I also tried the below . does not work :( "SMSContent": { "id": "jsonschema.net/Request/Data/SMSContent", "type": "string", "minLength": 1, "maxLength": 160, "pattern": "[0-9A-Za-z]{1,160}" } Commented May 5, 2016 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. Commented May 5, 2016 at 21:59
  • 1
    Possible duplicate of Using RegEx in JSON Schema Commented Sep 11, 2016 at 9:34
  • You need to add a $ to indicate the end of the string like this: "pattern": "[a-zA-Z]{1,160}$" Commented Sep 27, 2016 at 11:52

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.