Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

required keyword for empty string #885

Closed
soulcm opened this issue Nov 15, 2018 · 2 comments
Closed

required keyword for empty string #885

soulcm opened this issue Nov 15, 2018 · 2 comments
Labels

Comments

@soulcm
Copy link

soulcm commented Nov 15, 2018

What version of Ajv are you using? Does the issue happen if you use the latest version?

Ajv options object

{
  allErrors: true,
  jsonPointers: false, 
  coerceTypes: true,
  validateSchema: false
}

JSON Schema

{
  "type": "object",
  "properties": {
    "test": {
      "type": "string"
    }
  },
  "required": ["test"]
}

Sample data

{
  "test": ""
}

Your code

  ajv.validate(schema, data)
  console.log(ajv.errors)

Validation result, data AFTER validation, error messages

  the ajv.erros is null

What results did you expect?
how can I validate the empty string to use required keyword, or another solution

@epoberezkin
Copy link
Member

You can use other JSON schema keywords, e. g. minLength for strings.

@m-jahanbakhsh
Copy link

m-jahanbakhsh commented Oct 23, 2019

Unfortunately, if someone fills the field with spaces it will be valid because space counts as a character.
you can use addKeyword method for check isNotEmpty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants