<select id="pref">
<option>380</option>
<option>7</option>
</select>
<input type="text" id="num">
<script>
repl=()=>num.value = num.value.replace(/\D/g, '').replace(/\d{9,}/g, m=>m.slice(0,9+pref.selectedIndex));
num.oninput = repl;
pref.onchange = repl;
</script>