32 lines
660 B
Go
32 lines
660 B
Go
package entity
|
|
|
|
import (
|
|
"net/mail"
|
|
"strings"
|
|
|
|
userentity "spark-server/internal/module/user/entity"
|
|
)
|
|
|
|
// ParseTarget classifies a single client string as email or mainland mobile.
|
|
func ParseTarget(raw string) (Channel, string, bool) {
|
|
raw = strings.TrimSpace(raw)
|
|
if raw == "" {
|
|
return 0, "", false
|
|
}
|
|
if strings.Contains(raw, "@") {
|
|
email := userentity.NormalizeEmail(raw)
|
|
if email == "" {
|
|
return 0, "", false
|
|
}
|
|
if _, err := mail.ParseAddress(email); err != nil {
|
|
return 0, "", false
|
|
}
|
|
return ChannelEmail, email, true
|
|
}
|
|
phone := NormalizePhone(raw)
|
|
if phone == "" {
|
|
return 0, "", false
|
|
}
|
|
return ChannelPhone, phone, true
|
|
}
|