validatil

package
v0.0.0-...-8d6dda1 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

README

校验工具,如邮箱格式,字符串长度等

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecValid

func ExecValid(val, rule string, args ...string) error

数据验证 @param val 字符串 @param rule 验证规则,见Valid()注释 @param args 变参参数 @return 返回验证错误

func Valid

func Valid(params url.Values, rules map[string][]string) (map[string]interface{}, map[string]string)

参数验证 规则中,required表示必传参数,有无值则是另外一回事 验证规则有以下(大小写不敏感): 1、required 参数必传,有无值则是另外一回事,使用示例:"required" 1、unempty 值不能为空,使用示例:"unempty" 2、min 最小值验证,使用示例:"min:1" 3、max 最大值验证,使用示例:"max:1000" 4、minlen、mincount 最小长度验证,使用示例:"minlen:2" 说明:count是字符个数校验,len是字节个数校验,如"地球",如果是len,则是6个字节,如果是count,则是2个字符 5、maxlen、maxcount 最大长度验证,使用示例:"maxcount:255" 说明:count是字符个数校验,len是字节个数校验,如"地球",如果是len,则是6个字节,如果是count,则是2个字符 6、len、count 字符串长度验证,使用示例:"len:40" 说明:count是字符个数校验,len是字节个数校验,如"地球",如果是len,则是6个字节,如果是count,则是2个字符 7、email 邮箱格式验证,使用示例:"email" 8、tel 座机号码格式验证,使用示例:"tel" 9、mobile 手机号码格式验证,使用示例:"mobile" 10、phone 电话号码格式验证,包括手机号码和座机号码,使用示例:"phone" 11、enum 参数值验证,参数值只能是其中指定的一个值,使用示例:"enum:男:女:保密" 12、range 参数区间,适用于数字变化范围,使用示例:"range:1:100" 13、int,int8,int32,int64,float32,float64,string 只要有这些数据类型的字段,则表示类型转换,使用示例:"int64" 14、zipcode 邮政编码验证,使用示例:"zipcode" 15、ip IP地址格式验证,使用示例:"ip" 16、alpha 字符验证,字符必须是大小写字母,使用示例:"alpha" 17、numeric 数字验证,必须是0-9中的数字,使用示例:"numeric" 18、alphanumeric 大小写字母和数字验证,值必须是大小写字母和数字,使用示例:"alphanumeric" 19、alphadash 大小写字母、数字、横杠(-_)验证,使用示例:"alphadash" 20、gt,lt,gte,lte 大于、小于、大于等于或者小于等于指定数值:使用示例:"gt:0" 说明:如果是等于指定数值,使用enum,如"enum:1",即等于1 21、regexp 正则校验,使用示例:"regexp:[a-zA-z0-9\.\-\_]{10}",第一个冒号后面的表示正则规则 ############################################ @param params url.Values参数 @param rules 验证规则 @return 返回验证后通过的数据 @return 返回错误的map

Types

This section is empty.

Jump to

Keyboard shortcuts

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