<PackageReference Include="NJsonSchema" Version="11.0.0" />

DateFormatValidator

Validator for "Date" format.
using Newtonsoft.Json.Linq; using System; using System.Globalization; using System.Runtime.CompilerServices; namespace NJsonSchema.Validation.FormatValidators { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public class DateFormatValidator : IFormatValidator { public string Format { get; } = "date"; public ValidationErrorKind ValidationErrorKind { get; } = ValidationErrorKind.DateExpected; public bool IsValid(string value, JTokenType tokenType) { if (tokenType != JTokenType.Date) { if (DateTime.TryParseExact(value, "yyyy-MM-dd", null, DateTimeStyles.None, out DateTime result)) return result.Date == result; return false; } return true; } } }