PageSourceSearch

https://neva-alushta.ru/wp-content/themes/neva/assets/js/maskPhone.js?ver=6.6.2

js neva-alushta.ru collected 2026-10-09 22:41:27 UTC 1,314 bytes, 42 lines download raw bytes

1function maskPhone(selector, masked = '+7 (___) ___-__-__') {
2	const elems = document.querySelectorAll(selector);
3
4	function mask(event) {
5		const keyCode = event.keyCode;
6		const template = masked,
7			def = template.replace(/\D/g, ""),
8			val = this.value.replace(/\D/g, "");
9		console.log(template);
10		let i = 0,
11			newValue = template.replace(/[_\d]/g, function (a) {
12				return i < val.length ? val.charAt(i++) || def.charAt(i) : a;
13			});
14		i = newValue.indexOf("_");
15		if (i !== -1) {
16			newValue = newValue.slice(0, i);
17		}
18		let reg = template.substr(0, this.value.length).replace(/_+/g,
19			function (a) {
20				return "\\d{1," + a.length + "}";
21			}).replace(/[+()]/g, "\\$&");
22		reg = new RegExp("^" + reg + "$");
23		if (!reg.test(this.value) || this.value.length < 5 || keyCode > 47 && keyCode < 58) {
24			this.value = newValue;
25		}
26		if (event.type === "blur" && this.value.length < 5) {
27			this.value = "";
28		}
29
30	}
31
32	for (const elem of elems) {
33		elem.addEventListener("input", mask);
34		elem.addEventListener("focus", mask);
35		elem.addEventListener("blur", mask);
36	}
37	
38}
39
40// use
41
42// maskPhone('селектор элементов', 'маска, если маску не передать то будет работать стандартная +7 (___) ___-__-__');

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.