Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $( document ).ready(function() {
- let currentPhoneInputValue;
- $("*[data-name='Phone 5']").focus(function(e) {
- currentPhoneInputValue = $(this).val();
- })
- $("*[data-name='Phone 5']").keypress(function(e) {
- if(currentPhoneInputValue.length === 3 && e.which === 56) {
- e.preventDefault();
- } else {
- currentPhoneInputValue = $(this)
- }
- });
- let fields = document.querySelectorAll('input[data-name="Phone 5"]');
- for (let i = 0; i < fields.length; i++) {
- fields[i].addEventListener("paste", function(e) {
- console.log(e.target.id);
- var pastedText = undefined;
- if (window.clipboardData && window.clipboardData.getData) {
- pastedText = window.clipboardData.getData('Text');
- } else {
- var clipboardData = (e.originalEvent || e).clipboardData;
- if (clipboardData && clipboardData.getData) {
- pastedText = clipboardData.getData('text/plain');
- }
- if(pastedText[0] === "8") {
- console.log("starts from 8");
- e.target.value = "+7 " + pastedText.split("").slice(1).join("")
- } else {
- e.target.value = pastedText
- }
- e.preventDefault();
- return false;
- }
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement