我有暫定的新電話號碼 - 559907XXXX。我需要將其格式更改爲(111)-111-1111。這個電話號碼是在跨度和輸入字段ot,所以我無法使用掩碼。使用javascript的DOM中的電話號碼格式
$('.phone-number').mask('(000)-000-0000');
尋找解決方案使用REG前。請幫助
我有暫定的新電話號碼 - 559907XXXX。我需要將其格式更改爲(111)-111-1111。這個電話號碼是在跨度和輸入字段ot,所以我無法使用掩碼。使用javascript的DOM中的電話號碼格式
$('.phone-number').mask('(000)-000-0000');
尋找解決方案使用REG前。請幫助
<html>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
$("#phone").blur(function (e) {
var x = e.target.value.replace(/\D/g, '').match(/(\d{3})(\d{3})(\d{4})/);
e.target.value = '(' + x[1] + ') ' + x[2] + '-' + x[3];
});
});
</script>
<body>
<p>Masked on the blur event (remove focus).</p>
<input type="text" id="phone" placeholder="(555) 555-5555"/>
</body>
</html>
告訴我們你到目前爲止試過了什麼? – spirit