mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +08:00
doc: update doc and example for validator
This commit is contained in:
@@ -112,7 +112,7 @@ func ContainLetter(str string) bool {
|
||||
}
|
||||
|
||||
// IsJSON checks if the string is valid JSON.
|
||||
// Play: https://go.dev/play/p/sRS6c4K8jGk
|
||||
// Play: https://go.dev/play/p/8Kip1Itjiil
|
||||
func IsJSON(str string) bool {
|
||||
var js json.RawMessage
|
||||
return json.Unmarshal([]byte(str), &js) == nil
|
||||
@@ -370,7 +370,7 @@ func IsGBK(data []byte) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsNumberStr check if the value is Number(integer, float) or not.
|
||||
// IsNumberStr check if the value is number(integer, float) or not.
|
||||
// Play: todo
|
||||
func IsNumber(v any) bool {
|
||||
return IsInt(v) || IsFloat(v)
|
||||
|
||||
@@ -285,8 +285,8 @@ func ExampleIsIntStr() {
|
||||
func ExampleIsJSON() {
|
||||
result1 := IsJSON("{}")
|
||||
result2 := IsJSON("{\"name\": \"test\"}")
|
||||
result3 := IsIntStr("")
|
||||
result4 := IsIntStr("abc")
|
||||
result3 := IsJSON("")
|
||||
result4 := IsJSON("abc")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
Reference in New Issue
Block a user