validate.go 535 B

1234567891011121314151617181920212223242526272829
  1. package util
  2. import "regexp"
  3. var (
  4. emailRegex = regexp.MustCompile(`^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$`)
  5. phoneRegex = regexp.MustCompile(`^\+?[1-9]\d{6,14}$`)
  6. )
  7. func IsValidEmail(email string) bool {
  8. return emailRegex.MatchString(email)
  9. }
  10. func IsValidPhone(phone string) bool {
  11. return phoneRegex.MatchString(phone)
  12. }
  13. func NormalizePage(page, pageSize int64) (int64, int64) {
  14. if page <= 0 {
  15. page = 1
  16. }
  17. if pageSize <= 0 {
  18. pageSize = 20
  19. }
  20. if pageSize > 100 {
  21. pageSize = 100
  22. }
  23. return page, pageSize
  24. }