private void ValidateString(JsonSchemaModel schema)
{
if (schema == null)
{
return;
}
if (!TestType(schema, JsonSchemaType.String))
{
return;
}
ValidateNotDisallowed(schema);
string value = _reader.Value.ToString();
if (schema.MaximumLength != null && value.Length > schema.MaximumLength)
{
RaiseError("String '{0}' exceeds maximum length of {1}.".FormatWith(CultureInfo.InvariantCulture, value, schema.MaximumLength), schema);
}
if (schema.MinimumLength != null && value.Length < schema.MinimumLength)
{
RaiseError("String '{0}' is less than minimum length of {1}.".FormatWith(CultureInfo.InvariantCulture, value, schema.MinimumLength), schema);
}
if (schema.Patterns != null)
{
foreach (string pattern in schema.Patterns)
{
if (!Regex.IsMatch(value, pattern))
{
RaiseError("String '{0}' does not match regex pattern '{1}'.".FormatWith(CultureInfo.InvariantCulture, value, pattern), schema);
}
}
}
}