1(function($){ 2 3 $.fn.emailPhoneValidator = function(options) { 4 5 var settings = $.extend({ 6 type: ['mail', 'phone'], 7 selectorMail: '.type-email input', 8 selectorPhone: '.type-phone input', 9 isPopup: false, 10 inputWrapper: '.tpl-field', 11 popupTime: 4000, 12 mask: '+9 (999) 999-99-99', 13 isMask: false, 14 mailErrText: 'ÐÑ Ð²Ð²ÐµÐ»Ð¸ невеÑнÑй E-mail адÑеÑ!', 15 phoneErrText: 'ÐÑ Ð²Ð²ÐµÐ»Ð¸ невеÑнÑй Ð½Ð¾Ð¼ÐµÑ ÑелеÑона!' 16 }, options); 17 18 return this.each(function() { 19 20 var $this = $(this); 21 22 if (settings.type.includes('mail')) { 23 24 $this.on('blur', settings.selectorMail, function(){ 25 var $this = $(this), 26 isValidEmail = isEmail($this.val()); 27 28 // еÑли вÑбÑана вÑплÑваÑÑÐ°Ñ ÑоÑма подÑказки 29 if (settings.isPopup) { 30 31 if (isValidEmail) { 32 $this.closest(settings.inputWrapper).removeClass('field-error'); 33 } else { 34 $this.parent().attr('data-tip', settings.mailErrText); 35 setTimeout(function(){ 36 $this.parent().removeAttr('data-tip'); 37 },settings.popupTime); 38 $this.closest(settings.inputWrapper).addClass('field-error'); 39 } 40 41 } 42 // еÑли вÑбÑана подÑказка в виде ÑекÑÑа над ÑоÑмой 43 else { 44 45 if (isValidEmail) { 46 $this.closest(settings.inputWrapper).removeClass('field-error'); 47 $this.siblings('.error-message').remove(); 48 } else { 49 if(!$this.siblings('.error-message').length) { 50 $('<div class="error-message">'+ settings.mailErrText +'</div>').insertBefore($this); 51 } 52 $this.closest(settings.inputWrapper).addClass('field-error'); 53 } 54 55 } 56 57 }); 58 } 59 60 if (settings.type.includes('phone')) { 61 62 $this.find(settings.selectorPhone).attr('type', 'tel'); 63 64 if (settings.isMask) { 65 $this.find(settings.selectorPhone).inputmask(settings.mask); 66 $.ajaxSetup({ 67 complete: function(){ 68 $this.find(settings.selectorPhone).inputmask(settings.mask); 69 } 70 }); 71 } 72 73 $this.on('blur', settings.selectorPhone, function(){ 74 var $this = $(this), 75 isValidPhone = isPhone($this.val()); 76 77 // еÑли вÑбÑана вÑплÑваÑÑÐ°Ñ ÑоÑма подÑказки 78 if (settings.isPopup) { 79 80 if (isValidPhone) { 81 $this.closest(settings.inputWrapper).removeClass('field-error'); 82 } else { 83 $this.parent().attr('data-tip', settings.phoneErrText); 84 setTimeout(function(){ 85 $this.parent().removeAttr('data-tip'); 86 },settings.popupTime); 87 $this.closest(settings.inputWrapper).addClass('field-error'); 88 } 89 90 } 91 // еÑли вÑбÑана подÑказка в виде ÑекÑÑа над ÑоÑмой 92 else { 93 94 if (isValidPhone) { 95 $this.closest(settings.inputWrapper).removeClass('field-error'); 96 $this.siblings('.error-message').remove(); 97 } else { 98 if(!$this.siblings('.error-message').length) { 99 $('<div class="error-message">'+ settings.phoneErrText +'</div>').insertBefore($this); 100 } 101 $this.closest(settings.inputWrapper).addClass('field-error'); 102 } 103 104 } 105 106 }); 107 } 108 109 110 }); 111 112 function isEmail(email) { 113 var regex = /^[\w-\.]+@[\w-]+\.[a-z]{2,4}$/i; 114 return regex.test(email); 115 } 116 117 function isPhone(phone) { 118 var regex = /^[- +()0-9]{5,20}$/; 119 return regex.test(phone); 120 } 121 122 }; 123 124 125})( jQuery );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.