Comprehensive collection of 26 format validators covering date/time, network, data encoding, and OpenAPI specification formats. Each format supports both full validation and fast validation modes.
RFC3339-compliant date and time validation with optional timezone handling.
type DateTimeFormats =
| "date" // Full-date: YYYY-MM-DD
| "time" // Time with mandatory timezone
| "date-time" // Date-time with mandatory timezone
| "iso-time" // Time with optional timezone
| "iso-date-time" // Date-time with optional timezone
| "duration"; // RFC3339 duration formatUsage Examples:
// Date format (YYYY-MM-DD)
const dateSchema = { type: "string", format: "date" };
ajv.validate(dateSchema, "2023-12-25"); // true
ajv.validate(dateSchema, "2023-02-30"); // false (invalid date in full mode)
// Time format (HH:MM:SSZ or HH:MM:SS±HH:MM)
const timeSchema = { type: "string", format: "time" };
ajv.validate(timeSchema, "14:30:00Z"); // true
ajv.validate(timeSchema, "14:30:00+05:30"); // true
ajv.validate(timeSchema, "14:30:00"); // false (timezone required)
// ISO time format (timezone optional)
const isoTimeSchema = { type: "string", format: "iso-time" };
ajv.validate(isoTimeSchema, "14:30:00"); // true
ajv.validate(isoTimeSchema, "14:30:00Z"); // true
// Date-time format
const dateTimeSchema = { type: "string", format: "date-time" };
ajv.validate(dateTimeSchema, "2023-12-25T14:30:00Z"); // true
// Duration format (P[n]Y[n]M[n]DT[n]H[n]M[n]S)
const durationSchema = { type: "string", format: "duration" };
ajv.validate(durationSchema, "P1Y2M3DT4H5M6S"); // true
ajv.validate(durationSchema, "PT30M"); // true (30 minutes)Comprehensive URI validation supporting various URI types and templates.
type URIFormats =
| "uri" // Full URI with scheme
| "uri-reference" // URI reference (full or relative)
| "uri-template" // RFC6570 URI template
| "url"; // URL record (deprecated)Usage Examples:
// URI format (requires scheme)
const uriSchema = { type: "string", format: "uri" };
ajv.validate(uriSchema, "https://example.com/path"); // true
ajv.validate(uriSchema, "ftp://files.example.com"); // true
ajv.validate(uriSchema, "/relative/path"); // false (no scheme)
// URI reference (allows relative URIs)
const uriRefSchema = { type: "string", format: "uri-reference" };
ajv.validate(uriRefSchema, "https://example.com"); // true
ajv.validate(uriRefSchema, "/relative/path"); // true
ajv.validate(uriRefSchema, "../parent/path"); // true
// URI template
const uriTemplateSchema = { type: "string", format: "uri-template" };
ajv.validate(uriTemplateSchema, "/users/{id}"); // true
ajv.validate(uriTemplateSchema, "/search{?q,limit}"); // trueEmail addresses, hostnames, and IP address validation.
type NetworkFormats =
| "email" // Email address
| "hostname" // RFC1034 hostname
| "ipv4" // IPv4 address
| "ipv6"; // IPv6 addressUsage Examples:
// Email format
const emailSchema = { type: "string", format: "email" };
ajv.validate(emailSchema, "user@example.com"); // true
ajv.validate(emailSchema, "user.name+tag@example.org"); // true
ajv.validate(emailSchema, "invalid.email"); // false
// Hostname format
const hostnameSchema = { type: "string", format: "hostname" };
ajv.validate(hostnameSchema, "example.com"); // true
ajv.validate(hostnameSchema, "sub.example.com"); // true
ajv.validate(hostnameSchema, "localhost"); // true
// IPv4 format
const ipv4Schema = { type: "string", format: "ipv4" };
ajv.validate(ipv4Schema, "192.168.1.1"); // true
ajv.validate(ipv4Schema, "10.0.0.1"); // true
ajv.validate(ipv4Schema, "999.999.999.999"); // false
// IPv6 format
const ipv6Schema = { type: "string", format: "ipv6" };
ajv.validate(ipv6Schema, "2001:0db8:85a3:0000:0000:8a2e:0370:7334"); // true
ajv.validate(ipv6Schema, "::1"); // true (loopback)
ajv.validate(ipv6Schema, "2001:db8::1"); // true (compressed)Regular expressions, UUIDs, and JSON pointer validation.
type DataFormats =
| "regex" // Valid regular expression
| "uuid" // RFC4122 UUID
| "json-pointer" // RFC6901 JSON pointer
| "json-pointer-uri-fragment" // JSON pointer as URI fragment
| "relative-json-pointer"; // Relative JSON pointerUsage Examples:
// Regular expression format
const regexSchema = { type: "string", format: "regex" };
ajv.validate(regexSchema, "^[a-z]+$"); // true
ajv.validate(regexSchema, "[invalid"); // false (unclosed bracket)
// UUID format
const uuidSchema = { type: "string", format: "uuid" };
ajv.validate(uuidSchema, "550e8400-e29b-41d4-a716-446655440000"); // true
ajv.validate(uuidSchema, "urn:uuid:550e8400-e29b-41d4-a716-446655440000"); // true
// JSON pointer format
const jsonPtrSchema = { type: "string", format: "json-pointer" };
ajv.validate(jsonPtrSchema, "/foo/bar"); // true
ajv.validate(jsonPtrSchema, "/foo/0"); // true
ajv.validate(jsonPtrSchema, ""); // true (root)
ajv.validate(jsonPtrSchema, "/foo~0bar"); // true (escaped ~)
// JSON pointer URI fragment
const jsonPtrFragSchema = { type: "string", format: "json-pointer-uri-fragment" };
ajv.validate(jsonPtrFragSchema, "#/foo/bar"); // true
ajv.validate(jsonPtrFragSchema, "#"); // true (root)Numeric and data formats from OpenAPI 3.0.0 specification.
type OpenAPIFormats =
| "byte" // Base64 encoded data
| "int32" // Signed 32-bit integer
| "int64" // Signed 64-bit integer
| "float" // Float number
| "double" // Double precision number
| "password" // Password string (hint for UI)
| "binary"; // Binary string (unchecked)Usage Examples:
// Base64 byte format
const byteSchema = { type: "string", format: "byte" };
ajv.validate(byteSchema, "SGVsbG8gV29ybGQ="); // true
ajv.validate(byteSchema, "invalid base64!"); // false
// Integer formats (used with number type)
const int32Schema = { type: "number", format: "int32" };
ajv.validate(int32Schema, 2147483647); // true (max int32)
ajv.validate(int32Schema, 2147483648); // false (exceeds int32)
ajv.validate(int32Schema, 3.14); // false (not integer)
const int64Schema = { type: "number", format: "int64" };
ajv.validate(int64Schema, 9007199254740991); // true (max safe integer)
// Float and double formats
const floatSchema = { type: "number", format: "float" };
ajv.validate(floatSchema, 3.14159); // true
ajv.validate(floatSchema, 42); // true
// Password format (passes validation, UI hint)
const passwordSchema = { type: "string", format: "password" };
ajv.validate(passwordSchema, "any-string"); // true
// Binary format (passes validation, unchecked)
const binarySchema = { type: "string", format: "binary" };
ajv.validate(binarySchema, "\u0000\u0001\u0002"); // trueUnion type containing all supported format names.
type FormatName =
| "date" | "time" | "date-time" | "iso-time" | "iso-date-time" | "duration"
| "uri" | "uri-reference" | "uri-template" | "url"
| "email" | "hostname" | "ipv4" | "ipv6"
| "regex" | "uuid" | "json-pointer" | "json-pointer-uri-fragment" | "relative-json-pointer"
| "byte" | "int32" | "int64" | "float" | "double" | "password" | "binary";type FormatName =
| "date" | "time" | "date-time" | "iso-time" | "iso-date-time" | "duration"
| "uri" | "uri-reference" | "uri-template" | "url"
| "email" | "hostname" | "ipv4" | "ipv6"
| "regex" | "uuid" | "json-pointer" | "json-pointer-uri-fragment" | "relative-json-pointer"
| "byte" | "int32" | "int64" | "float" | "double" | "password" | "binary";
type DefinedFormats = {
[key in FormatName]: Format;
};