I want to block writing special characters in input of Vue.
First, I made a function like below.
blockSpecialChar(e) {
console.log(e.keyCode);
const k = e.keyCode;
return (
(k > 64 && k < 91) ||
(k > 96 && k < 123) ||
k == 8 ||
(k >= 48 && k <= 57)
);
}
And I connect it with the code below.
<input
type="test"
placeholder="phone"
v-model="pin.phoneNumber"
v-on:keypress.prevent="blockSpecialChar(e)"
/>
But when I type, it says 'e is not defined'. How can I make this correctly? Thank you so much for reading.
v-on:keypress.prevent="blockSpecialChar"orv-on:keypress.prevent="e => blockSpecialChar(e)"