validatorzh

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2021 License: GPL-3.0 Imports: 13 Imported by: 0

README

validator-zh

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

使用方法

以 gin 为例其他框架类似.

import(
  zh "github.com/glepnir/validatorzh"
)

type CreateUserSchema struct {
	UserName       string `json:"username" validate:"required" label:"用户姓名"`
	Phone          string `json:"phone" validate:"required,mobile" label:"联系电话"`
	IdCard         string `json:"phone" 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

func LanguageValidate added in v1.0.2

func LanguageValidate(i interface{}) error

func Validate

func Validate(i interface{}) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL