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