Skip to content

Latest commit

 

History

History

svelte

README.md

@inputmask/svelte

Svelte action for Inputmask.

Install

npm install @inputmask/svelte inputmask

Install the latest versions. svelte (4 or newer, including Svelte 5) and inputmask are peer dependencies.

Usage

<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.

Extensions

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();

Build and test

npm run build --workspace=@inputmask/svelte
npm run test --workspace=@inputmask/svelte

The core package must be built first (npm run build && npm run types at the repository root).