rule.go 963 B

1234567891011121314151617181920212223242526
  1. package validator
  2. import (
  3. "github.com/go-playground/validator/v10"
  4. "regexp"
  5. )
  6. func isoPhone(fl validator.FieldLevel) bool {
  7. ok, _ := regexp.MatchString(`^\+(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)\d{1,14}$`, fl.Field().String())
  8. return ok
  9. }
  10. func chinesePhone(fl validator.FieldLevel) bool {
  11. ok, _ := regexp.MatchString(`^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$`, fl.Field().String())
  12. return ok
  13. }
  14. func idCard(fl validator.FieldLevel) bool {
  15. isIdCard, _ := regexp.MatchString(`^[1-9]\d{7}((0\d)|(1[0-2]))(([0-2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0-2]\d)|3[0-1])\d{3}([0-9]|X)$`, fl.Field().String())
  16. return isIdCard
  17. }
  18. func chineseName(fl validator.FieldLevel) bool {
  19. var hzRegexp = regexp.MustCompile("^[\u4e00-\u9fa5]{2,8}$")
  20. return hzRegexp.MatchString(fl.Field().String())
  21. }