Сработает при снятии фокуса с поля.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<input type="text" id="someid">
<script>
document.getElementById('someid').onchange = function() {
if ( /^\d{3}\d{3}\d{2}\d{2}$/.exec(this.value) ) {
this.value = this.value.replace(/(\d{3})(\d{3})(\d{2})(\d{2})/, function(str, aaa, bbb, cc, dd) {
return '+7(' + aaa + ')' + bbb + '-' + cc + '-' + dd;
});
}
}
</script>
</body>
</html>