validators.go 717 B

1234567891011121314151617181920212223242526272829303132333435
  1. package utl
  2. import (
  3. "regexp"
  4. )
  5. var (
  6. patternEmail string = "^([.]?[a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+"
  7. patternPhone string = "^(13[0-9]|14[57]|15[0-35-9]|18[0-9]|17[0-9]|16[7]|19[1])\\d{8}$"
  8. expEmail *regexp.Regexp = regexp.MustCompile(patternEmail)
  9. expPhone *regexp.Regexp = regexp.MustCompile(patternPhone)
  10. )
  11. func IsEmail(email string) bool {
  12. return expEmail.MatchString(email)
  13. }
  14. func IsPhone(phone string) bool {
  15. return expPhone.MatchString(phone)
  16. }
  17. func IsPhoneSimple(phone string) bool {
  18. if len(phone) != 11 {
  19. return false
  20. }
  21. return phone[0] == 49
  22. }
  23. func IsAlpha(alpha string) bool {
  24. return false
  25. }
  26. func IsSafePasswd(passwd string) bool {
  27. return false
  28. }