allow only number in phone number input (#10)
All checks were successful
delpoy / build-and-deploy (push) Successful in 41s
All checks were successful
delpoy / build-and-deploy (push) Successful in 41s
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
export let type = 'text';
|
||||
export let value: string | null = null;
|
||||
export let placeholder: string | null = null;
|
||||
export let pattern: RegExp | null = null;
|
||||
export let required = false;
|
||||
export let disabled = false;
|
||||
export let readonly = false;
|
||||
@@ -91,10 +92,22 @@
|
||||
bind:this={inputElement}
|
||||
autocomplete="off"
|
||||
on:input={(e) => {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
value = e.target?.value;
|
||||
input(e);
|
||||
if (pattern && !pattern.test(e.target?.value)) {
|
||||
if (inputElement?.value.endsWith(e.data)) {
|
||||
value = e.target?.value.substring(0, -e.data.length);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return input(e);
|
||||
}}
|
||||
on:paste={(e) => {
|
||||
if (
|
||||
pattern &&
|
||||
!pattern.test((e.clipboardData || window.clipboardData).getData('text'))
|
||||
) {
|
||||
e.preventDefault();
|
||||
}
|
||||
}}
|
||||
on:click={click}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user