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

ByteFormatValidator

Validator for "Byte" format.
using Newtonsoft.Json.Linq; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; namespace NJsonSchema.Validation.FormatValidators { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public class ByteFormatValidator : IFormatValidator { private const string Base64Expression = "^[a-zA-Z0-9\\+/]*={0,3}$"; public string Format { get; } = "byte"; public ValidationErrorKind ValidationErrorKind { get; } = ValidationErrorKind.Base64Expected; public bool IsValid(string value, JTokenType tokenType) { if (value.Length % 4 == 0) return Regex.IsMatch(value, "^[a-zA-Z0-9\\+/]*={0,3}$", RegexOptions.None); return false; } } }