validatorzh

package module
Version: v0.0.0-...-50e89a5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2020 License: GPL-3.0 Imports: 14 Imported by: 0

README

validator-zh

validator的中文提示,新增手机号码和身份证号码.

使用方法

以 gin 为例其他框架类似.

import(
  zh "github.com/glepnir/validator-zh"
)

type CreateUserSchema struct {
	UserName       string `json:"username" validate:"required" label:"用户姓名"`
	Phone          string `json:"phone" validate:"required,mobile" label:"联系电话"`
	IdCard         string `json:"idcard" validate:"required,idcard" label:"身份证号码"`
}

var users User
_ = c.ShoudBindBodyWith(users,binding.JSON)

err := zh.Validate(users)
if err !=nil{
  c.json(http.StatusBadRequest,gin.H{
    "message": err.Error(),
  })
}
---------output:
"用户姓名为必填字段"
"联系电话格式错误"
"身份证号码格式错误"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EchoValidatorZh

type EchoValidatorZh struct {
	// contains filtered or unexported fields
}

func (*EchoValidatorZh) Validate

func (c *EchoValidatorZh) Validate(i interface{}) error

type GinValidatorZh

type GinValidatorZh struct {
	// contains filtered or unexported fields
}

func (*GinValidatorZh) Engine

func (v *GinValidatorZh) Engine() interface{}

func (*GinValidatorZh) ValidateStruct

func (v *GinValidatorZh) ValidateStruct(obj interface{}) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL