新增患者手机号
This commit is contained in:
@@ -64,3 +64,26 @@ func MaskNameStr(str string, maskType int) string {
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
// MaskPhoneStr 手机号、固话加密
|
||||
// 固话:0510-89754815 0510-8****815
|
||||
// 手机号:18221234158 18*******58
|
||||
func MaskPhoneStr(phone string) string {
|
||||
if phone == "" {
|
||||
return phone
|
||||
}
|
||||
|
||||
// 使用正则表达式匹配固定电话
|
||||
phonePattern := `(0[0-9]{2,3}[\-]?[2-9][0-9]{6,7}[\-]?[0-9]?)`
|
||||
isFixedLine := regexp.MustCompile(phonePattern).MatchString(phone)
|
||||
|
||||
if isFixedLine {
|
||||
// 匹配到固定电话
|
||||
// 替换匹配的部分为固定格式
|
||||
return regexp.MustCompile(`(0[0-9]{2,3}[\-]?[2-9])[0-9]{3,4}([0-9]{3}[\-]?[0-9]?)`).ReplaceAllString(phone, "$1****$2")
|
||||
} else {
|
||||
// 匹配到手机号
|
||||
// 替换匹配的部分为固定格式
|
||||
return regexp.MustCompile(`(1[0-9]{1})[0-9]{7}([0-9]{2})`).ReplaceAllString(phone, "$1*******$2")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user