Advertisement
bongzilla

Untitled

Jan 14th, 2021
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  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. } else {
  36. e.target.value = pastedText
  37. }
  38.  
  39. e.preventDefault();
  40. return false;
  41. }
  42. });
  43. }
  44.  
  45. });
  46.  
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement