> For the complete documentation index, see [llms.txt](https://docs.internetobject.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.internetobject.org/schema-definition-language/data-types/string.md).

# String Types

The **`string`** type validates text. It has two **predefined shortcuts** that are `string` with a built-in pattern: [Email](/schema-definition-language/data-types/string/email.md) and [URL](/schema-definition-language/data-types/string/url.md).

> `date`, `time`, and `datetime` are **not** string subtypes — they are their own types with their own values. See [Date and Time](/schema-definition-language/data-types/date-and-time.md).
>
> For how strings are *written* (open, quoted, raw), see [Strings](/structure-and-syntax/values/string.md).

## The string family

| Type     | Is                                          |
| -------- | ------------------------------------------- |
| `string` | any text                                    |
| `email`  | `string` validated against an email pattern |
| `url`    | `string` validated against a URL pattern    |

```ruby
contact: email, site: url
---
~ a@b.com, 'https://example.com'    # ✓
~ notanemail, 'https://example.com' # ✗ invalid-email
```

> **Quote values containing `:` or spaces** (URLs, times-of-day, "Last, First"). An unquoted `https://x.com` is misread because the open string ends at `:`.

## TypeDef

A `string` MemberDef accepts only the options below. Any other key is invalid.

| Option        | Type            | Description                                                     |
| ------------- | --------------- | --------------------------------------------------------------- |
| `type`        | string          | `string`, `email`, or `url`. First positional value.            |
| `default`     | string          | Value used when the member is omitted. Second positional value. |
| `choices`     | array of string | Restricts the value to a fixed set. Third positional value.     |
| `pattern`     | string          | A regular expression the value must match.                      |
| `flags`       | string          | Regex flags for `pattern` (e.g. `i`).                           |
| `len`         | int ≥ 0         | Exact length in characters.                                     |
| `minLen`      | int ≥ 0         | Minimum length.                                                 |
| `maxLen`      | int ≥ 0         | Maximum length.                                                 |
| `format`      | string          | Serialization form: `auto` (default), `regular`, `raw`.         |
| `encloser`    | string          | Quote character used when serializing: `"` (default) or `'`.    |
| `escapeLines` | bool            | Whether to escape line breaks on serialization.                 |
| `optional`    | bool            | If `true`, the member may be omitted. Shorthand: `?` suffix.    |
| `null`        | bool            | If `true`, the member may be `null`. Shorthand: `*` suffix.     |

> **`len` precedence.** When `len` is set, `minLen` and `maxLen` are ignored.

## Constraints

### minLen / maxLen / len

```ruby
name: { string, minLen: 5, maxLen: 20 }
---
~ Ethan              # ✓
~ Alexandra Daddario # ✓
~ Leo                # ✗ invalid-min-length
```

### pattern

A regular expression. Use a [raw string](/structure-and-syntax/values/string/raw-strings.md) (`r'…'`) to avoid escaping backslashes.

```ruby
ssn: { string, pattern: r'^[0-9]{3}-[0-9]{2}-[0-9]{4}$' }
---
~ '123-45-6789'   # ✓
~ '12345678'      # ✗ invalid-pattern
```

### choices

```ruby
dept: { string, choices: [cs, mech, civil] }
---
~ cs     # ✓
~ art    # ✗ invalid-choice
```

> Quote choices that look like numbers or contain commas, e.g. `["19.02, 72.85"]`, so they are treated as strings.

## Optional, nullable & defaults

```ruby
nickname?*: { string, anonymous }   # optional + nullable, default "anonymous"
---
~ {}      # ✓ → "anonymous" (omitted, default applies)
~ N       # ✓ → null
~ John    # ✓ → "John"
```

| Input                   | Result                                                         |
| ----------------------- | -------------------------------------------------------------- |
| valid text              | the string                                                     |
| fails a constraint      | `invalid-*` error (`invalid-min-length`, `invalid-pattern`, …) |
| `N`, nullable (`*`)     | `null`                                                         |
| `N`, not nullable       | `null-not-allowed` error                                       |
| omitted, `default` set  | the default                                                    |
| omitted, optional (`?`) | absent                                                         |
| omitted, required       | `value-required` error                                         |

> **Use the `*` suffix for nullability** — keyed `null:` is not yet honored (see below).

## Implementation status (beta)

* Keyed `optional:` works; keyed `null:` is not yet honored — use the `*` suffix.

## See Also

* [Strings (value syntax)](/structure-and-syntax/values/string.md)
* [Email](/schema-definition-language/data-types/string/email.md) · [URL](/schema-definition-language/data-types/string/url.md)
* [Date and Time](/schema-definition-language/data-types/date-and-time.md)
* [TypeDef](/schema-definition-language/advanced-schema-concepts/typedef.md) · [MemberDef](/schema-definition-language/advanced-schema-concepts/memberdef.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.internetobject.org/schema-definition-language/data-types/string.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
