react-formbridge
Browse documentation
Field buildersv1.0.2

field.text()

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(), and field.masked()
  • trim(), min(), max(), pattern(), and transform() are the most used methods on text fields
  • The same schema works on web and React Native without changes
Text.web.tsxtsx
1const 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}
9const { Form, fields } = useFormBridge(schema)
10
11return (
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:

MethodTypeDescription
min(length, message?)length: numberSets the minimum accepted string length.
max(length, message?)length: numberSets 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: RegExpOverrides the low-level format regex used by preset string builders.
trim()() => thisTrims whitespace before validation and submit.
lowercase()() => thisLowercases the value before storing it.
uppercase()() => thisUppercases the value before storing it.
nonEmpty(message?)message?: stringRejects empty strings and whitespace-only input (stricter than required(), which only checks for presence).
length(exact, message?)exact: numberRequires an exact character count - handy for fixed-size codes like tax IDs, IBAN fragments, or reference numbers.
between(min, max, message?)min: number, max: numberShorthand 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 | FieldReferenceRequires equality with another field value (supports ref() for nested paths). Classic use: confirm-password.
sameAs(fieldName, message?)fieldName: string | FieldReferenceAlias for matches() with more explicit confirmation semantics.

Recipes

Patterns that showcase text-specific strengths.

Username with character constraints

Username.tsxtsx
1const 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
1const 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
1const schema = {
2 displayName: field.text('Display name')
3 .trim()
4 .min(1)
5 .max(50)
6 .transform((value) => value.replace(/\s{2,}/g, ' ')),
7}