This commit is contained in:
2022-04-07 15:20:21 +08:00
parent 19ea9c5a16
commit 811536bea4
35 changed files with 466 additions and 543 deletions

21
pkg/validator/phone.go Normal file
View File

@@ -0,0 +1,21 @@
package validator
import (
"errors"
"regexp"
"strings"
)
var (
rxPhone = regexp.MustCompile(`^(13|14|15|16|17|18|19)\d{9}$`)
ErrPhoneFormat = errors.New("phone format error")
)
func ValidateRxPhone(phone string) error {
phone = strings.TrimSpace(phone)
if !rxPhone.MatchString(phone) {
return ErrPhoneFormat
}
return nil
}