diff --git a/README.md b/README.md index 453d736..39a70e3 100644 --- a/README.md +++ b/README.md @@ -562,8 +562,6 @@ import "github.com/duke-git/lancet/v2/random" [[doc](https://github.com/duke-git/lancet/blob/main/docs/random.md#UUIdV4)] [[play](https://go.dev/play/p/_Z9SFmr28ft)] - - ### 15. Retry package is for executing a function repeatedly until it was successful or canceled by the context. ```go @@ -746,8 +744,6 @@ import "github.com/duke-git/lancet/v2/slice" [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#KeyBy)] [[play](https://go.dev/play/p/uXod2LWD1Kg)] - - ### 17. Strutil package contains some functions to manipulate string. ```go @@ -859,34 +855,90 @@ import "github.com/duke-git/lancet/v2/validator" #### Function list: -- [ContainChinese](https://github.com/duke-git/lancet/blob/main/docs/validator.md#ContainChinese) -- [ContainLetter](https://github.com/duke-git/lancet/blob/main/docs/validator.md#ContainLetter) -- [ContainLower](https://github.com/duke-git/lancet/blob/main/docs/validator.md#ContainLower) -- [ContainUpper](https://github.com/duke-git/lancet/blob/main/docs/validator.md#ContainUpper) -- [IsAlpha](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsAlpha) -- [IsAllUpper](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsAllUpper) -- [IsAllLower](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsAllLower) -- [IsBase64](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsBase64) -- [IsChineseMobile](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsChineseMobile) -- [IsChineseIdNum](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsChineseIdNum) -- [IsChinesePhone](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsChinesePhone) -- [IsCreditCard](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsCreditCard) -- [IsDns](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsDns) -- [IsEmail](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsEmail) -- [IsEmptyString](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsEmptyString) -- [IsFloatStr](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsFloatStr) -- [IsNumberStr](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsNumberStr) -- [IsJSON](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsJSON) -- [IsRegexMatch](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsRegexMatch) -- [IsIntStr](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsIntStr) -- [IsIp](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsIp) -- [IsIpV4](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsIpV4) -- [IsIpV6](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsIpV6) -- [IsStrongPassword](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsStrongPassword) -- [IsUrl](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsUrl) -- [IsWeakPassword](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsWeakPassword) -- [IsZeroValue](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsZeroValue) -- [IsGBK](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsGBK) +- **ContainChinese** : check if the string contain mandarin chinese. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#ContainChinese)] + [[play](https://go.dev/play/p/7DpU0uElYeM)] +- **ContainLetter** : check if the string contain at least one letter. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#ContainLetter)] + [[play](https://go.dev/play/p/lqFD04Yyewp)] +- **ContainLower** : check if the string contain at least one lower case letter a-z. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#ContainLower)] + [[play](https://go.dev/play/p/Srqi1ItvnAA)] +- **ContainUpper** : check if the string contain at least one upper case letter A-Z. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#ContainUpper)] + [[play](https://go.dev/play/p/CmWeBEk27-z)] +- **IsAlpha** : checks if the string contains only letters (a-zA-Z). + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsAlpha)] + [[play](https://go.dev/play/p/7Q5sGOz2izQ)] +- **IsAllUpper** : check if the string is all upper case letters A-Z. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsAllUpper)] + [[play](https://go.dev/play/p/ZHctgeK1n4Z)] +- **IsAllLower** : check if the string is all lower case letters a-z. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsAllLower)] + [[play](https://go.dev/play/p/GjqCnOfV6cM)] +- **IsBase64** : check if the string is base64 string. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsBase64)] + [[play](https://go.dev/play/p/sWHEySAt6hl)] +- **IsChineseMobile** : check if the string is chinese mobile number. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsChineseMobile)] + [[play](https://go.dev/play/p/GPYUlGTOqe3)] +- **IsChineseIdNum** : check if the string is chinese id card. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsChineseIdNum)] + [[play](https://go.dev/play/p/d8EWhl2UGDF)] +- **IsChinesePhone** : check if the string is chinese phone number.(xxx-xxxxxxxx or xxxx-xxxxxxx.) + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsChinesePhone)] + [[play](https://go.dev/play/p/RUD_-7YZJ3I)] +- **IsCreditCard** : check if the string is credit card. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsCreditCard)] + [[play](https://go.dev/play/p/sNwwL6B0-v4)] +- **IsDns** : check if the string is dns. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsDns)] + [[play](https://go.dev/play/p/jlYApVLLGTZ)] +- **IsEmail** : check if the string is a email address. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsEmail)] + [[play](https://go.dev/play/p/Os9VaFlT33G)] +- **IsEmptyString** : check if the string is empty. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsEmptyString)] + [[play](https://go.dev/play/p/dpzgUjFnBCX)] +- **IsFloatStr** : check if the string can convert to a float. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#LOYwS_Oyl7U)] + [[play](https://go.dev/play/p/LOYwS_Oyl7U)] +- **IsNumberStr** : check if the string can convert to a number. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsNumberStr)] + [[play](https://go.dev/play/p/LzaKocSV79u)] +- **IsJSON** : check if the string is valid JSON. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsJSON)] + [[play](https://go.dev/play/p/sRS6c4K8jGk)] +- **IsRegexMatch** : check if the string match the regexp. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsRegexMatch)] + [[play](https://go.dev/play/p/z_XeZo_litG)] +- **IsIntStr** : check if the string can convert to a integer. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsIntStr)] + [[play](https://go.dev/play/p/jQRtFv-a0Rk)] +- **IsIp** : check if the string is ip. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsIp)] + [[play](https://go.dev/play/p/FgcplDvmxoD)] +- **IsIpV4** : check if the string is ipv4. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsIpV4)] + [[play](https://go.dev/play/p/zBGT99EjaIu)] +- **IsIpV6** : check if the string is ipv6. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsIpV6)] + [[play](https://go.dev/play/p/AHA0r0AzIdC)] +- **IsStrongPassword** : check if the string is strong password. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsStrongPassword)] + [[play](https://go.dev/play/p/QHdVcSQ3uDg)] +- **IsUrl** : check if the string is url. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsUrl)] + [[play](https://go.dev/play/p/pbJGa7F98Ka)] +- **IsWeakPassword** : check if the string is weak password. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsWeakPassword)] + [[play](https://go.dev/play/p/wqakscZH5gH)] +- **IsZeroValue** : check if value is a zero value. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsZeroValue)] + [[play](https://go.dev/play/p/UMrwaDCi_t4)] +- **IsGBK** : check if data encoding is gbk. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsGBK)] + [[play](https://go.dev/play/p/E2nt3unlmzP)] ### 20. xerror package implements helpers for errors. diff --git a/README_zh-CN.md b/README_zh-CN.md index bc2b965..4511b6e 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -857,34 +857,91 @@ import "github.com/duke-git/lancet/v2/validator" #### 函数列表: -- [ContainChinese](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#ContainChinese) -- [ContainLetter](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#ContainLetter) -- [ContainLower](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#ContainLower) -- [ContainUpper](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#ContainUpper) -- [IsAlpha](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsAlpha) -- [IsAllUpper](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsAllUpper) -- [IsAllLower](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsAllLower) -- [IsBase64](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsBase64) -- [IsChineseMobile](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsChineseMobile) -- [IsChineseIdNum](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsChineseIdNum) -- [IsChinesePhone](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsChinesePhone) -- [IsCreditCard](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsCreditCard) -- [IsDns](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsDns) -- [IsEmail](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsEmail) -- [IsEmptyString](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsEmptyString) -- [IsFloatStr](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsFloatStr) -- [IsNumberStr](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsNumberStr) -- [IsJSON](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsJSON) -- [IsRegexMatch](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsRegexMatch) -- [IsIntStr](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsIntStr) -- [IsIp](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsIp) -- [IsIpV4](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsIpV4) -- [IsIpV6](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsIpV6) -- [IsStrongPassword](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsStrongPassword) -- [IsUrl](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsUrl) -- [IsWeakPassword](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsWeakPassword) -- [IsZeroValue](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsZeroValue) -- [IsGBK](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsGBK) +- **ContainChinese** : 验证字符串是否包含中文字符。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#ContainChinese)] + [[play](https://go.dev/play/p/7DpU0uElYeM)] +- **ContainLetter** : 验证字符串是否包含至少一个英文字母。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#ContainLetter)] + [[play](https://go.dev/play/p/lqFD04Yyewp)] +- **ContainLower** : 验证字符串是否包含至少一个英文小写字母。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#ContainLower)] + [[play](https://go.dev/play/p/Srqi1ItvnAA)] +- **ContainUpper** : 验证字符串是否包含至少一个英文大写字母。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#ContainUpper)] + [[play](https://go.dev/play/p/CmWeBEk27-z)] +- **IsAlpha** : 验证字符串是否只包含英文字母。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsAlpha)] + [[play](https://go.dev/play/p/7Q5sGOz2izQ)] +- **IsAllUpper** : 验证字符串是否全是大写英文字母。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsAllUpper)] + [[play](https://go.dev/play/p/ZHctgeK1n4Z)] +- **IsAllLower** : 验证字符串是否全是小写英文字母。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsAllLower)] + [[play](https://go.dev/play/p/GjqCnOfV6cM)] +- **IsBase64** : 验证字符串是否是base64编码。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsBase64)] + [[play](https://go.dev/play/p/sWHEySAt6hl)] +- **IsChineseMobile** : 验证字符串是否是中国手机号码。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsChineseMobile)] + [[play](https://go.dev/play/p/GPYUlGTOqe3)] +- **IsChineseIdNum** : 验证字符串是否是中国身份证号码。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsChineseIdNum)] + [[play](https://go.dev/play/p/d8EWhl2UGDF)] +- **IsChinesePhone** : 验证字符串是否是中国电话座机号码(xxx-xxxxxxxx or xxxx-xxxxxxx.)。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsChinesePhone)] + [[play](https://go.dev/play/p/RUD_-7YZJ3I)] +- **IsCreditCard** : 验证字符串是否是信用卡号码。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsCreditCard)] + [[play](https://go.dev/play/p/sNwwL6B0-v4)] +- **IsDns** : 验证字符串是否是有效dns。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsDns)] + [[play](https://go.dev/play/p/jlYApVLLGTZ)] +- **IsEmail** : 验证字符串是否是有效电子邮件地址。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsEmail)] + [[play](https://go.dev/play/p/Os9VaFlT33G)] +- **IsEmptyString** : 验证字符串是否是空字符串。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsEmptyString)] + [[play](https://go.dev/play/p/dpzgUjFnBCX)] +- **IsFloatStr** : 验证字符串是否是可以转换为浮点数。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#LOYwS_Oyl7U)] + [[play](https://go.dev/play/p/LOYwS_Oyl7U)] +- **IsNumberStr** : 验证字符串是否是可以转换为数字。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsNumberStr)] + [[play](https://go.dev/play/p/LzaKocSV79u)] +- **IsJSON** : 验证字符串是否是有效json。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsJSON)] + [[play](https://go.dev/play/p/sRS6c4K8jGk)] +- **IsRegexMatch** : 验证字符串是否可以匹配正则表达式。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsRegexMatch)] + [[play](https://go.dev/play/p/z_XeZo_litG)] +- **IsIntStr** : 验证字符串是否是可以转换为整数。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsIntStr)] + [[play](https://go.dev/play/p/jQRtFv-a0Rk)] +- **IsIp** : 验证字符串是否是ip地址。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsIp)] + [[play](https://go.dev/play/p/FgcplDvmxoD)] +- **IsIpV4** : 验证字符串是否是ipv4地址。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsIpV4)] + [[play](https://go.dev/play/p/zBGT99EjaIu)] +- **IsIpV6** : 验证字符串是否是ipv6地址。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsIpV6)] + [[play](https://go.dev/play/p/AHA0r0AzIdC)] +- **IsStrongPassword** : 验证字符串是否是强密码:(字母+数字+特殊字符)。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsStrongPassword)] + [[play](https://go.dev/play/p/QHdVcSQ3uDg)] +- **IsUrl** : 验证字符串是否是url。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsUrl)] + [[play](https://go.dev/play/p/pbJGa7F98Ka)] +- **IsWeakPassword** : 验证字符串是否是弱密码(只包含字母+数字)。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsWeakPassword)] + [[play](https://go.dev/play/p/wqakscZH5gH)] +- **IsZeroValue** : 判断传入的参数值是否为零值。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsZeroValue)] + [[play](https://go.dev/play/p/UMrwaDCi_t4)] +- **IsGBK** : 检查数据编码是否为gbk(汉字内部代码扩展规范)。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsGBK)] + [[play](https://go.dev/play/p/E2nt3unlmzP)] + ### 20. xerror 包实现一些错误处理函数 diff --git a/docs/validator_zh-CN.md b/docs/validator_zh-CN.md index 909999d..4de7a05 100644 --- a/docs/validator_zh-CN.md +++ b/docs/validator_zh-CN.md @@ -459,8 +459,6 @@ func main() { - - ### IsEmptyString

验证字符串是否是空字符串

@@ -488,7 +486,6 @@ func main() { - ### IsFloatStr

验证字符串是否是可以转换为浮点数

@@ -574,8 +571,6 @@ func main() { ``` - - ### IsRegexMatch

验证字符串是否可以匹配正则表达式

@@ -601,7 +596,6 @@ func main() { - ### IsIntStr

验证字符串是否是可以转换为整数

diff --git a/validator/validator.go b/validator/validator.go index 39dcecb..e1dbb50 100644 --- a/validator/validator.go +++ b/validator/validator.go @@ -69,7 +69,7 @@ func ContainUpper(str string) bool { return false } -// ContainLower check if the string contain at least one lower case letter A-Z. +// ContainLower check if the string contain at least one lower case letter a-z. // Play: https://go.dev/play/p/Srqi1ItvnAA func ContainLower(str string) bool { for _, r := range str { @@ -192,7 +192,7 @@ func IsChineseIdNum(id string) bool { return chineseIdMatcher.MatchString(id) } -// ContainChinese check if the string contain mandarin chinese.. +// ContainChinese check if the string contain mandarin chinese. // Play: https://go.dev/play/p/7DpU0uElYeM func ContainChinese(s string) bool { return chineseMatcher.MatchString(s)