Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使用本机javascript将诸如“1234567891234”之类的数字格式化为“123-45678-912-34”?有很多可用的解决方案,但我想知道哪一个是最好的?请指教
如下所示:
var unformatted="1234567891234" var groups=/^(\d{3})(\d{5})(\d{3})(\d{2}$)/.exec(unformatted) var formatted=groups[1]+"-"+groups[2]+"-"+groups[3]+"-"+groups[4] console.log(formatted)