Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const inputField = document.querySelector("#ff_4_input_text");
- inputField.addEventListener("keydown", function (event) {
- if (
- event.key === "Backspace" ||
- event.key === "Delete" ||
- event.key === "ArrowLeft" ||
- event.key === "ArrowRight" ||
- event.key === "ArrowUp" ||
- event.key === "ArrowDown" ||
- event.key === "Tab" ||
- (event.key.startsWith("Num") && event.key.length > 3)
- ) {
- return;
- }
- if (/^\d$/.test(event.key)) {
- const currentValue = event.target.value;
- if (!currentValue.startsWith("+30")) {
- event.target.value = "+30" + currentValue;
- }
- } else {
- event.preventDefault();
- }
- });
- inputField.addEventListener("paste", function (event) {
- const pastedText = (event.clipboardData || window.clipboardData).getData("text");
- if (!/^\d*$/.test(pastedText)) {
- event.preventDefault();
- } else {
- const currentValue = event.target.value;
- event.target.value = "+30" + currentValue;
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement