Yaroma11,
Добавление знаков в номер телефона
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
</head>
<body>
<input oninput="proverka(this)" onfocus="setCursorPosition(6, this)" >
<script>
function setCursorPosition(pos, elem) {
elem.focus();
if (elem.setSelectionRange) {
elem.setSelectionRange(pos, pos);
} else if (elem.createTextRange) {
var range = elem.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
}
function proverka(el) {
var matrix = "+375 (00) 000-00-00",
i = 0,
val = el.value.replace(/\D/g, '');
!val && (val = "375")
matrix = matrix.replace(/\d/g, function (a) {
return val.charAt(i++) || "_"
})
el.value = matrix;
i = matrix.lastIndexOf(val.substr(-1));
i < matrix.length && i > 3 ? i++ : (i = 6)
setCursorPosition(i, el)
};
document.querySelector('input').oninput()
</script>
</body>
</html>