The simplest component of an input mask with validation for digits of a given format, which can contain arbitrary non-numeric characters
npm i svelte-mask
<script>
import PhoneMaskInput from 'svelte-mask'
</script>
<PhoneMaskInput originHolder="+1(000)0000000" />
import { h } from 'preact';
import { render } from 'preact';
import React from "react";
import { useState, useEffect, useRef } from "preact/hooks";
import PhoneMaskInput from "svelte-mask";
const App = () => {
const inputContainer = useRef(null);
useEffect(() => {
let widget = new PhoneMaskInput({
target: inputContainer.current,
props: {
onComplete: v => setMsg(() => v)
}
})
return () => {};
}, []);
let [msg, setMsg] = useState('');
return <div className="App">
<p style={{ cursor: 'pointer', userSelect: null }}>
Enter complete number:
<b className={'counter'}>
{msg}
</b>
</p>
<div ref={inputContainer}></div>
</div>
};
render(<App />, document.body);
Look up working example here
import PhoneMaskInput from 'svelte-mask'
const app = new PhoneMaskInput({
target: document.getElementById('app'),
props: {
originHolder: '+1(000)0000000'
}
})
export default app
<link rel="stylesheet" href="https://unpkg.com/svelte-mask@latest/build/css/app.css">
<div id="app"></div>
<script src="https://unpkg.com/svelte-mask@latest/build/bundle.js"></script>
<script>
createMaskInput('app', '+7(999)9999999')
</script>
Name | size(min) | appreciated by the community | transparent mask | uneven rendering | stable |
---|---|---|---|---|---|
svelte-mask | 5kb | - | + | - | + |
@imask/svelte | 59kb | + | - | + | + |
svelte-input-mask | 13kb | + | - | + | + |
svelte-masked-input | ? | - | + | - | ? |
svelte-number-format | ? | - | ? | ? | ? |
if you found this component useful, you can show it by clicking on the star