<input type="text"> <script> document.querySelector('input').oninput = function() { var str = this.value; if(str.indexOf('8') == 0) { str = str.replace('8','+7'); this.value = str; } } </script>