Format string as phone number in JavaScript/Lodash -
there following phone number string: '+79021234567'. how can format string '+7 902 123-45-67'? can manually substring, may there more elegant way? in advance!
str.substring(start, end)
seem applicable way, although not seem elegant:
> str = '+79021234567' > console.log([[str.substring(0, 2), str.substring(2, 5), str.substring(5, 8)].join(" "), str.substring(8, 10), str.substring(10)].join("-")); +7 902 123-45-67
Comments
Post a Comment