簡體   English   中英

在MS Ajax中將號碼格式化為電話號碼

[英]Format a number as phone number in MS Ajax

如何使用MS Ajax格式將數字格式化為電話號碼(例如(45)879-2658)。

在C#中,我可以使用{0:(###)### - ####}格式化此數字。

但不確定如何在MS Ajax中為整數實現此格式。

我不知道C#,這是你如何在javascript中進行圖片格式化:

format = "(###)###-####"
input = 1234567890
formatted = format.replace(/#/g, [].shift.bind(String(input).split("")))
// result: "(123)456-7890"

要處理比圖片更短的字符串,請嘗試使用稍微冗長的代碼:

chars = String(input).split("")
formatted = format.replace(/#/g, function() { return chars.shift() || "" })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM