| 1234567891011121314151617181920212223242526272829 |
- package util
- import "regexp"
- var (
- emailRegex = regexp.MustCompile(`^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$`)
- phoneRegex = regexp.MustCompile(`^\+?[1-9]\d{6,14}$`)
- )
- func IsValidEmail(email string) bool {
- return emailRegex.MatchString(email)
- }
- func IsValidPhone(phone string) bool {
- return phoneRegex.MatchString(phone)
- }
- func NormalizePage(page, pageSize int64) (int64, int64) {
- if page <= 0 {
- page = 1
- }
- if pageSize <= 0 {
- pageSize = 20
- }
- if pageSize > 100 {
- pageSize = 100
- }
- return page, pageSize
- }
|