Advertisement
bongzilla

Untitled

Jan 14th, 2021
1,024
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $( document ).ready(function() {
  2.     let currentPhoneInputValue;
  3.  
  4.     $("*[data-name='Phone 5']").focus(function(e) {
  5.         currentPhoneInputValue = $(this).val();
  6.     })
  7.  
  8.     $("*[data-name='Phone 5']").keypress(function(e) {
  9.         if(currentPhoneInputValue.length === 3 && e.which === 56) {
  10.             e.preventDefault();
  11.         } else {
  12.             currentPhoneInputValue = $(this)
  13.         }
  14.     });
  15.  
  16.     let fields = document.querySelectorAll('input[data-name="Phone 5"]');
  17.  
  18.     for (let i = 0; i < fields.length; i++) {
  19.         fields[i].addEventListener("paste", function(e) {
  20.             console.log(e.target.id);
  21.            
  22.             var pastedText = undefined;
  23.  
  24.             if (window.clipboardData && window.clipboardData.getData) {
  25.                 pastedText = window.clipboardData.getData('Text');
  26.             } else {
  27.                 var clipboardData = (e.originalEvent || e).clipboardData;
  28.                 if (clipboardData && clipboardData.getData) {
  29.                     pastedText = clipboardData.getData('text/plain');
  30.                 }
  31.  
  32.                 if(pastedText[0] === "8") {
  33.                     console.log("starts from 8");
  34.                     e.target.value = "+7 " + pastedText.split("").slice(1).join("")
  35.                 }
  36.  
  37.                 e.preventDefault();
  38.                 return false;
  39.             }
  40.         });
  41.     }
  42.  
  43. });
  44.  
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement