DocsForms & drafts
Get started

Search Subtly documentation

Search by a task, helper name or framework.

Forms & drafts

normalize()

Clean up common input formatting.

Try the example

Choose a format, edit the sample value and normalize it. Compare the original with the output. Formatting cleanup does not verify that an address or phone number is valid.

Cleaned outputWaiting for input

Choose a format, then normalize.

Actual npm package · local demonstration

Add it to your project

  1. Copy the HTML. Place the markup inside the component where this behavior belongs. The preview’s visual classes are website styles; use your own design system.
  2. Connect the behavior. Copy the JavaScript tab and call its exported mount(element) after your component’s elements exist. Replace simulated delays and data operations with your own application code.
  3. Clean up. Call the returned cleanup when the component unmounts. It aborts the example’s listeners and releases the helper’s timers, observers or state.

API and lifecycle

Use the pure whitespace(), email() and phone() helpers to clean common formatting. Each returns a string; email trims and lowercases only the domain, while phone removes common separators.

Interface
whitespace, email, phone; not full validation
Lifecycle
These helpers create no listeners or timers, so there is no destroy step. Apply the returned value explicitly on blur or submission.

Accessibility and safety

Implementation notes

Initialize after the DOM is available. Keep native controls and keyboard interactions intact; release listeners and timers on unmount.

Normalization is not validation. Avoid rewriting text on every keystroke because that can move the caret or interrupt composition. Preserve email local-part casing.

What to check

Try extra spaces, a mixed-case email local part and formatted phone numbers. Confirm invalid data is still validated and typing is not interrupted.