Skip to contents

Share field-type checks between model definitions and validation consumers. Requiredness and other field constraints are handled by the caller.

Usage

form_value_matches_type(x, type)

Arguments

x

Scalar value to check, without coercion.

type

One of string, email, integer, number, boolean, latitude, longitude, date, or datetime.

Value

One logical value; FALSE for missing or incompatible values, unsupported types, or classed values such as factors, Date, and POSIXct.

Details

Dates require YYYY-MM-DD; datetimes require YYYY-MM-DDTHH:MM:SSZ. Both must parse and format back to the identical string, using UTC for datetimes. Emails require nonempty local and domain parts, a domain dot, and no whitespace or additional at signs. Mailbox existence is not checked. Numeric values must be finite; integers must have no fractional part. Coordinates are decimal degrees: latitude is in [-90, 90] and longitude in [-180, 180], including both endpoints. Numeric text is not coerced.

Examples

form_value_matches_type("contact@example.org", "email")
#> [1] TRUE
form_value_matches_type("2026-10-18T12:00:00Z", "datetime")
#> [1] TRUE