Svelte action for Inputmask.
npm install @inputmask/svelte inputmaskInstall the latest versions. svelte (4 or newer, including Svelte 5) and
inputmask are peer dependencies.
<script>
import { inputmask } from "@inputmask/svelte";
let phone = "";
</script>
<!-- Phone -->
<input use:inputmask={"+99 999 99 99"} bind:value={phone} />
<!-- Phone with extra options -->
<input use:inputmask={{ mask: "+99 999 99 99", clearIncomplete: true }} />
<!-- Email (register the email extension first) -->
<input use:inputmask={{ alias: "email" }} />The action accepts a mask string, a mask array or a full options object. Updating the parameter remasks the input while preserving the raw value, and the mask is removed automatically when the element is destroyed.
The core entry does not register optional aliases. Register the extensions you use once, before the component mounts:
import { registerDatetime } from "inputmask/extensions/date";
import { registerNumeric } from "inputmask/extensions/numeric";
registerDatetime();
registerNumeric();npm run build --workspace=@inputmask/svelte
npm run test --workspace=@inputmask/svelteThe core package must be built first (npm run build && npm run types at the
repository root).