go-ozzo / ozzo-validation

An idiomatic Go (golang) validation package. Supports configurable and extensible validation rules (validators) using normal language constructs instead of error-prone struct tags.
MIT License
3.76k stars 223 forks source link

LengthOfValue length of Chinese is wrong #149

Closed liuaiyuan closed 3 years ago

liuaiyuan commented 3 years ago
  var str = "hello"
  length, _ := validation.LengthOfValue(str)

  fmt.Println(length) // output: 5 ✅

  fmt.Println(utf8.RuneCountInString(str))  // output: 5 ✅
  var str = "你好"
  length, _ := validation.LengthOfValue(str)

  fmt.Println(length) // output: 6 ❌

  fmt.Println(utf8.RuneCountInString(str))  // output: 2 ✅
qiangxue commented 3 years ago

This is expected because LengthOfValue returns the byte length. To validate the rune length, use RuneLength

liuaiyuan commented 3 years ago

This is expected because LengthOfValue returns the byte length. To validate the rune length, use RuneLength

ok,thank you!!!!