json-schema-validator icon indicating copy to clipboard operation
json-schema-validator copied to clipboard

Can i customize which date is valid

Open ohadabraham opened this issue 3 years ago • 1 comments

when give in the schema : "name": { "type": "string", "format":"date" } and transfer to validate this : "2019-10-12 07:20:50.52Z" "2019-10-12T07:20:50.52Z"

2 Question regarding date validator :

  1. what is wrong ?
  2. can it support other date format ? i.e. : 02 Aug 2022, 09:58 that should be supported - for some reason it fail...

can i give the date format a date format i want to support? which is different from the :
private static final Pattern RFC3339_PATTERN = Pattern.compile( "^(\d{4})-(\d{2})-(\d{2})" // yyyy-MM-dd + "(Tt:(\d{2}):(\d{2})(\.\d+)?)?" // 'T'HH:mm:ss.milliseconds + "([Zz]|([+-])(\d{2}):?(\d{2}))?");

Thank u !

ohadabraham avatar Aug 02 '22 12:08 ohadabraham

The date and date-time format in JSON is standard, and it is not recommended to use other formats. If you have to do that, make it just a regular string and validate it with regex.

stevehu avatar Aug 02 '22 12:08 stevehu