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.
Choose a format, then normalize.
Add it to your project
- 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.
- 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. - 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.