All Projects → xnimorz → Svelte Input Mask

xnimorz / Svelte Input Mask

Input masking component for Svelte with simple API and rich customization

Projects that are alternatives of or similar to Svelte Input Mask

svelte-multiselect
Keyboard-friendly, accessible and highly customizable multi-select component
Stars: ✭ 91 (+62.5%)
Mutual labels:  input, svelte
React Native Masked Text
A pure javascript masked text and input text component for React-Native.
Stars: ✭ 1,368 (+2342.86%)
Mutual labels:  input, mask
svelte-search
Accessible, customizable Svelte search component
Stars: ✭ 17 (-69.64%)
Mutual labels:  input, svelte
Svelte Tags Input
Svelte tags input is a component to use with Svelte and easily enter tags and customize some options
Stars: ✭ 123 (+119.64%)
Mutual labels:  input, svelte
svelte-stripe-js
Everything you need to add Stripe Elements to your Svelte project
Stars: ✭ 139 (+148.21%)
Mutual labels:  svelte, credit-card
masked-input
Mask input with simple API and rich customization
Stars: ✭ 44 (-21.43%)
Mutual labels:  credit-card, mask
Cleave.js
Format input text content when you are typing...
Stars: ✭ 17,098 (+30432.14%)
Mutual labels:  input, credit-card
Svelte 3 Rollup Typescript Vscode
Starter for svelte 3/rollup/typescript/vscode
Stars: ✭ 43 (-23.21%)
Mutual labels:  svelte
Cfrs
Child Frame Read String
Stars: ✭ 46 (-17.86%)
Mutual labels:  input
Inputsystem
An efficient and versatile input system for Unity.
Stars: ✭ 1,013 (+1708.93%)
Mutual labels:  input
Pycard
A simple credit card validation Python library with no dependencies
Stars: ✭ 40 (-28.57%)
Mutual labels:  credit-card
Svelte Router
Simple Svelte Router for Single Page Applications (SPA).
Stars: ✭ 44 (-21.43%)
Mutual labels:  svelte
Sgdigittextfield
Elegant and Simplest Digit UITextField
Stars: ✭ 47 (-16.07%)
Mutual labels:  input
Jsx Lite
Write components once, run everywhere. Compiles to Vue, React, Solid, Angular, Svelte, and Liquid.
Stars: ✭ 1,015 (+1712.5%)
Mutual labels:  svelte
Vue Paycard
Credit card component made with Vue.js
Stars: ✭ 52 (-7.14%)
Mutual labels:  credit-card
Emv Nfc Paycard Enrollment
A Java library used to read and extract data from NFC EMV credit cards (Android/PCSC).
Stars: ✭ 1,009 (+1701.79%)
Mutual labels:  credit-card
Material Ui Password Field
A password field using Material-UI.
Stars: ✭ 54 (-3.57%)
Mutual labels:  input
Insert Text At Cursor
Fast crossbrowser insertion of text at cursor position in a textarea / input
Stars: ✭ 49 (-12.5%)
Mutual labels:  input
Bentools Etl
PHP ETL (Extract / Transform / Load) library with SOLID principles + almost no dependency.
Stars: ✭ 45 (-19.64%)
Mutual labels:  input
Brazilian Utils
Utils library for specific Brazilian businesses
Stars: ✭ 1,023 (+1726.79%)
Mutual labels:  mask

Mask input with simple API and rich customization.

If you need to create an input for:

  • credit card
  • phone number
  • date
  • birthday
  • numbers
  • Or other custom mask

This project could help you in all this situations!

Take a look at our demos: https://codesandbox.io/s/svelte-input-mask-demo-xurgr

How to use it:

Install it:

npm install --save svelte-input-mask

or if you're using yarn:

yarn add svelte-input-mask

Import MaskInput component:

import MaskInput from "svelte-input-mask/MaskInput.svelte";

Use it (for example for CreditCard):

<MaskInput alwaysShowMask maskChar="_" mask="0000-000000-00000" />

Add event listeners:

<script>
  import MaskInput from 'svelte-input-mask/MaskInput.svelte';

  let mask = '0000-0000-0000-0000';

  const handleChange = ({ detail }) => {
    console.log(detail.inputState.maskedValue); // stores the value of input

    if (detail.inputState.maskedValue.indexOf('34') === 0 || detail.inputState.maskedValue.indexOf('37') === 0) {
      mask = '0000-000000-00000';
      return;
    }

    mask = '0000-0000-0000-0000';
  };
</script>

<MaskInput alwaysShowMask maskChar="_" {mask} on:change={handleChange} />

Congrats! You made the first masked input :)

Checkout more usecases here: https://codesandbox.io/s/romantic-franklin-xurgr

Where to use?

Credit cards:

<MaskInput alwaysShowMask maskChar="_" mask="0000-000000-00000" />

Phones (you still can change prefixes, country code like in credit card example):

<MaskInput
  alwaysShowMask
  mask="+1 (000) 000 - 0000"
  size={20}
  showMask
  maskChar="_"
/>

Dates:

<script>
  import MaskInput from 'svelte-input-mask/MaskInput.svelte';

  let maskString = 'DD.MM.YYYY';
  let mask = '00.00.0000';

  const handleChange = ({ detail }) => {
    const value = detail.inputState.maskedValue;
    if (parseInt(value[6], 10) > 2) {
      maskString = 'DD.MM.YY';
      mask = '00.00.00';
    } else {
      maskString = 'DD.MM.YYYY';
      mask = '00.00.0000';
    }
  };
</script>

<MaskInput alwaysShowMask {maskString} {mask} on:change={handleChange}/>

Numbers:

<script>
  import NumberInput from 'svelte-input-mask/NumberInput.svelte';
</script>

<NumberInput />

Which props it has?

Mask input has next props:

Prop Default value Description
value - The value of the input. Will be processed to masked one. In this case you can control the value of the component
defaultValue - The default value of the input. Will be applied only during the first render
maskString - The mask string to show if there are no filled chars. It's length should be the same as mask. Example: 'DD.MM.YYYY'
maskChar '' In case you don't need a custom string you can define only a definite char for mask. Example: maskChar = '_' and mask = '0000-0000-0000-0000' will give: ____-____-____-____
mask - The mask of the input. Could be a credit card: '0000-0000-0000-0000', date: 00.00.0000 or whatever you want :) Doesn't work if reformat prop is setted
maskFormat regexp The regexp for custom formatting. You may use it if you want to define a specific mask. See example here: https://github.com/xnimorz/masked-input/blob/master/packages/input-core/src/index.ts#L16-L28
alwaysShowMask false Flag to show the mask
showMask false Show mask if there is any data in input
reformat - The function, which defines a custom formatting rules. In case if you can't describe the format only with mask (e.g. numbers). If you use this prop mask prop will be ignored

Svelte mask input pass all props that it doesn't handle right to input html element.

Quick start examples at local machine

git clone [email protected]:xnimorz/svelte-input-mask.git
cd svelte-input-mask/example
yarn install
yarn dev

Requirements:

Svelte should be installed in your project. Check the minimal Svelte version here: https://github.com/xnimorz/svelte-input-mask/blob/master/package.json#L42

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].