Вариант маски для ввода номера телефона
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
</head>
<body>
<input oninput="proverka(this)" onfocus="setCursorPosition(3, 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 = "+7(123)456-78-90",
i = 0,
val = el.value.replace(/\D/g, '');
!val && (val = "7")
matrix = matrix.replace(/\d/g, function (a) {
return val.charAt(i++) || "_"
})
el.value = matrix;
i = matrix.lastIndexOf(val.substr(-1));
i < matrix.length && i > 2 ? i++ : (i = 3)
setCursorPosition(i, el)
};
document.querySelector('input').oninput()
</script>
</body>
</html>