1、货币格式化
/**
* 货币格式化
* @param price
* @returns {string}
*/
export function formatPrice(price) {
if (typeof price !== 'number') return price
return String(Number(price).toFixed(2)).replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}
货币格式化效果:
2、手机号隐私保护,隐藏中间四位数字
/**
* 手机号隐私保护
* 隐藏中间四位数字
* @param mobile
* @returns {*}
*/
export function secrecyMobile(mobile) {
mobile = String(mobile)
if (!/\d{11}/.test(mobile)) {
return mobile
}
return mobile.replace(/(\d{3})(\d{4})(\d{4})/, '$1****$3')
}
手机隐私保护效果: