<input type="text" placeholder="you can input hiragana only">
*,
*:before,
*:after {
box-sizing: border-box;
}
body {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
input {
padding: 0.5rem;
width: 20rem;
}
let input = document.querySelector("input");
// disable event function
const disableEvent = e => {
e.preventDefault();
e.stopPropagation();
};
// disable paste
input.addEventListener("paste", disableEvent);
// disable drag&drop
input.addEventListener("drop", disableEvent);
// remove string
input.addEventListener("keyup", function(e) {
let tmp = [];
this.value.split("").forEach(function(item, i) {
if (item.match(/^[\u3040-\u309f]+$/)) {
tmp.push(item);
}
});
if (tmp.length > 0) {
this.value = tmp.join("");
} else {
this.value = "";
}
});
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.