The base builder for free-form strings. Use it for names, titles, slugs, comments, usernames, or any value that does not need a specialized builder.
- Inherits all shared methods from Base field builder
- This page is also the reference for the shared string-builder methods reused by
field.email(),field.password(),field.tel(),field.url(),field.textarea(),field.date(), andfield.masked() trim(),min(),max(),pattern(), andtransform()are the most used methods on text fields- The same schema works on web and React Native without changes
Text.web.tsxtsx
| 1 | const schema = { |
| 2 | fullName: field.text('Full name') |
| 3 | .required('Name is required') |
| 4 | .trim() |
| 5 | .min(2) |
| 6 | .max(80) |
| 7 | .pattern(/^[a-z\s'-]+$/i, 'Only letters and spaces.'),' |
| 8 | } |
| 9 | const { Form, fields } = useFormBridge(schema) |
| 10 | |
| 11 | return ( |
| 12 | <Form onSubmit={save}> |
| 13 | <fields.fullName /> |
| 14 | <Form.Submit>Save</Form.Submit> |
| 15 | </Form> |
| 16 | ) |
Defaults, inheritance & field methods
- defaultValue is
'' - type is
text - Shared methods: see Base field builder
- This page documents the string-specific layer added on top of the base builder
String builder methods:
| Method | Type | Description |
|---|---|---|
min(length, message?) | length: number | Sets the minimum accepted string length. |
max(length, message?) | length: number | Sets the maximum accepted string length. |
pattern(regex | regex[], message?) | RegExp | RegExp[] | Appends one or more accepted regex rules. |
patterns(regexes, message?) | RegExp[] | Alias for passing multiple accepted regex alternatives. |
format(regex, message?) | regex: RegExp | Overrides the low-level format regex used by preset string builders. |
trim() | () => this | Trims whitespace before validation and submit. |
lowercase() | () => this | Lowercases the value before storing it. |
uppercase() | () => this | Uppercases the value before storing it. |
nonEmpty(message?) | message?: string | Rejects empty strings and whitespace-only input (stricter than required(), which only checks for presence). |
length(exact, message?) | exact: number | Requires an exact character count - handy for fixed-size codes like tax IDs, IBAN fragments, or reference numbers. |
between(min, max, message?) | min: number, max: number | Shorthand for min(min).max(max) expressed as a single predicate with a combined message. |
oneOf(values, message?) | values: string[] | Accepts only values present in the allow-list. Useful for free-form inputs that must resolve to a known enum. |
notOneOf(values, message?) | values: string[] | Rejects values from a deny-list (reserved words, blocked usernames, forbidden slugs, etc.). |
matches(fieldName, message?) | fieldName: string | FieldReference | Requires equality with another field value (supports ref() for nested paths). Classic use: confirm-password. |
sameAs(fieldName, message?) | fieldName: string | FieldReference | Alias for matches() with more explicit confirmation semantics. |
Recipes
Patterns that showcase text-specific strengths.
Username with character constraints
Username.tsxtsx
| 1 | const schema = { |
| 2 | username: field.text('Username') |
| 3 | .required() |
| 4 | .trim() |
| 5 | .min(3) |
| 6 | .max(20) |
| 7 | .pattern(/^[a-z0-9_]+$/i, 'Letters, numbers, and underscores only.'), |
| 8 | } |
SEO slug with transform
Slug.tsxtsx
| 1 | const schema = { |
| 2 | slug: field.text('Slug') |
| 3 | .transform((value) => value.trim().toLowerCase().replace(/\s+/g, '-')) |
| 4 | .pattern(/^[a-z0-9-]+$/, 'Letters, numbers, and dashes only.'), |
| 5 | } |
Display name with whitespace cleanup
DisplayName.tsxtsx
| 1 | const schema = { |
| 2 | displayName: field.text('Display name') |
| 3 | .trim() |
| 4 | .min(1) |
| 5 | .max(50) |
| 6 | .transform((value) => value.replace(/\s{2,}/g, ' ')), |
| 7 | } |